如何将 msg.payload 存储到 ui_template 节点红色内的脚本变量中? [英] How to store a msg.payload into a script variable inside a ui_template node red?
本文介绍了如何将 msg.payload 存储到 ui_template 节点红色内的脚本变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了这段代码,但它不起作用
I wrote this code but it doesn't work
<script type = "text/javascript">
var msg = {{msg.payload}}
</script>
由于语法中的{",此方法将 {{msg.payload}} 值视为错误,我尝试了不同的方法,但没有任何效果,我想我遗漏了一些我不明白的东西,请我愿意接受任何建议.
this method consider the {{msg.payload}} value as an error due to the '{' in the syntax, I tried different ways, but nothing works, I guess I'm missing something that I don't understand, please I m open to any suggestion.
推荐答案
仪表板 UI 节点使用 Angular模板,所以你需要做一些不同的事情.
The Dashboard UI node uses Angular for it's templating so you need do things a little differently.
可以在此处找到一个很好的例子,但基本上类似于这个:
A good example can be found here but basically something like this:
<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>
这篇关于如何将 msg.payload 存储到 ui_template 节点红色内的脚本变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文