如何将 msg.payload 存储到 ui_template 节点红色内的脚本变量中?
How to store a msg.payload into a script variable inside a ui_template node red?
我写了这段代码,但它不起作用
<script type = "text/javascript">
var msg = {{msg.payload}}
</script>
由于语法中的“{”,此方法将 {{msg.payload}} 值视为错误,我尝试了不同的方法,但没有任何效果,我想我遗漏了一些我想知道的东西不明白,请我接受任何建议。
仪表板 UI 节点使用 Angular 作为模板,因此您需要做一些不同的事情。
可以找到一个很好的例子 here 但基本上是这样的:
<script>
//console.dir(scope) // this also works
//console.dir(scope.msg) // This doesn't because scope.msg doesn't yet exist
// Lambda function to access the Angular Scope
;(function(scope) {
//console.log('--- SCOPE ---')
//console.dir(scope) // this works but you only get it once (on startup)
//console.dir(scope.msg) // Doesn't work for because scope.msg doesn't yet exist
//Have to use $watch so we pick up new, incoming msg's
scope.$watch('msg.payload', function(newVal, oldVal) {
console.log('- Scope.msg -')
console.dir(scope.msg)
})
})(scope)
</script>
我写了这段代码,但它不起作用
<script type = "text/javascript">
var msg = {{msg.payload}}
</script>
由于语法中的“{”,此方法将 {{msg.payload}} 值视为错误,我尝试了不同的方法,但没有任何效果,我想我遗漏了一些我想知道的东西不明白,请我接受任何建议。
仪表板 UI 节点使用 Angular 作为模板,因此您需要做一些不同的事情。
可以找到一个很好的例子 here 但基本上是这样的:
<script>
//console.dir(scope) // this also works
//console.dir(scope.msg) // This doesn't because scope.msg doesn't yet exist
// Lambda function to access the Angular Scope
;(function(scope) {
//console.log('--- SCOPE ---')
//console.dir(scope) // this works but you only get it once (on startup)
//console.dir(scope.msg) // Doesn't work for because scope.msg doesn't yet exist
//Have to use $watch so we pick up new, incoming msg's
scope.$watch('msg.payload', function(newVal, oldVal) {
console.log('- Scope.msg -')
console.dir(scope.msg)
})
})(scope)
</script>