在 Node-Red 中 oneditsave 后,如何在下拉列表中显示先前选择的值(动态)? [英] How to show the previously selected values(dynamic) on a dropdown after oneditsave in Node-Red?

查看:74
本文介绍了在 Node-Red 中 oneditsave 后,如何在下拉列表中显示先前选择的值(动态)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义节点,其中包含两个相互独立的下拉菜单.

I'm having a custom node which includes two dropdowns which are independent to each other.

因此,第二个下拉列表的值会根据从第一个下拉列表中选择的值而变化.

So the second dropdown values changes, according to the selected value from the first drop down.

我现在尝试的是:

  • 用户拖动我的自定义节点 (iotinput) 从下拉菜单中选择值按下并单击完成".
  • 他再次拖动另一个自定义节点(iotinput),并选择不同的值并点击完成.
  • 所以目前有两个自定义节点.
  • 因此,当用户返回并单击其中一个节点时,它会应该显示我无法在之前选择的值当下.
  • 那么他将多少自定义节点拖入流程中,用户应该单击完成"后可以看到之前选择的值.

注意:以上所有内容都是我在没有部署流程的情况下完成的.

NOTE: All the above I'm doing it without deploying the flow.

我在这里面临的问题是,由于我是通过 ajax 调用加载下拉列表,因此无法加载之前选择的值.

The problem I'm facing here is, since I'm loading my dropdowns from an ajax call, I'm unable to load the previously selected values.

我检查了 Node-Red 中的内置节点,它有下拉菜单,其中的选项值是硬编码的.我能够成功地为文本框执行此操作.

I've checked the in-built nodes in Node-Red which has dropdowns, where the options values are hard coded. I was able to do it for a textbox successfully.

但是我一无所知,对于动态创建的下拉列表,我该怎么做?无论如何,Node-Red 可以做到吗?

But then I'm clueless, how could I do it for dropdowns which are getting created dynamically? Is there anyway in Node-Red to do it?

谢谢!

推荐答案

在节点的 oneditprepare 函数中,您可以访问其当前配置.这意味着一旦您将内容动态添加到 select 框中,您就可以根据节点属性设置选定的值.

In a node's oneditprepare function you have access to its current configuration. This means that once you've dynamically added to the contents to the select boxes, you can set the selected value based on the node property.

例如,如果一个节点有一个属性colour,你可以这样做:

For example, if a node has a property colour, you can do:

oneditprepare: function() {
    var node = this;

    $.ajax({
        url: 'http://example.com/colours.json'
        success: function(result) {
            // ... do whatever you need to build you select box
            // then set the current value:
            $('#mySelectBox').val(node.colour);
        }
    })
}

这篇关于在 Node-Red 中 oneditsave 后,如何在下拉列表中显示先前选择的值(动态)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆