Jquery/JavaScript 无法在 node-red 简单自定义节点中工作

Jquery/JavaScript not working in a node-red simple custom node

我正在为 Node-Red 开发自定义节点。下面是简单的 html,我正在尝试 select 使用 Jquery 的元素。 Jquery get/post/ajax 实际上有效,但 select 或无效。

<script type="text/javascript">
RED.nodes.registerType('air-conditioner',{
    category: 'function',
    color: '#a6bbcf',
    defaults: {
        name: {value:""},
        aclist:{value:""}
    },
    inputs:1,
    outputs:1,
    icon: "file.png",
    label: function() {
        return this.name||"air-conditioner";
    }
});

$( document ).ready(function() {
    alert("Name: "+$("#node-input-name").html());
    var root = 'http://172.20.0.107:8080/sitewhere/api/sites/bb105f8d-3150-41f5-b9d1-db04965668d4/assignments?includeDevice=false&includeAsset=true&includeSite=false';
    $.ajax({
        headers: {
            'Authorization':'Basic YWRtaW46cGFzc3dvcmQ=',
            'X-Sitewhere-Tenant':'atif12345'
        },
        url: root,
        method: 'GET'
    }).then(function(data) {
        debugger;
        $("#node-input-aclist").append('<option>hello</option>');
    });

});

<script type="text/x-red" data-template-name="air-conditioner">
    <div class="form-row">
        <label for="node-input-name"><i class="icon-tag"></i> Give this A.C a name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
 <div class="form-row">
        <label for="node-input-name"><i class="icon-tag"></i> Select A.C</label>
        <select id="node-input-aslist">
   <option>hello 1</option>
  </select>
    </div>
</script>

您不应该在 $( document ).ready() 中放置任何代码 - 只有在编辑节点时才会创建节点的编辑表单。

您应该将编辑表单所需的任何代码添加到节点的 oneditprepare 函数中。每次为节点构建编辑表单时都会调用它。

有关详细信息,请参阅 http://nodered.org/docs/creating-nodes/properties#custom-edit-behaviour