如何使用在道场工具包的当前 JS 文件中的另一个 JS 文件中创建的对话框变量



我在AddButtonEntryPoint.js文件中创建了对话框,我想在Form.js文件中访问该变量以在单击"提交"按钮后隐藏对话框 那么,我该如何调用。

这是我写的代码

添加按钮入口点.js

       var w = new Form({});
        var d = new Dialog({
            id: 'FormDialog',
            title: "Bridge Form",
            style: "width: 270px; height: 270px;",
            content: w,
            onHide: function() {
                // To prevent destroying the dialog before the animation ends
                setTimeout(lang.hitch(this, 'destroyRecursive'), 0);
            }
        });
            d.show();
        };          

形式.js

return declare( "mypackage.MyForm", Form, {
    repotextbox: new TextBox({
        name: "text",
        placeHolder: "Enter text here."
    } , dojo.doc.createElement('input')),
    DFMtextbox: new TextBox({
        name: "text",
        placeHolder: "Enter text here."
    } , dojo.doc.createElement('input')),
    submitButton: new Button({
        type: "submit",
        label: "Submit"
    }),
    constructor: function(args) {
        declare.safeMixin(this, args);
    },
    onSubmit: function() { 
        var repositoryID = this.repotextbox.get('value');
        xhr("https://samples.openweathermap.org/data/2.5/weather?q={repositoryID}",{ 
            // The URL of the request 
           method: "GET", 
            handleAs: "json", 
           }).then(
              function(data){ 
                alert(data.success + " " + JSON.stringify(data)); 
              }, 
              function(err){ 
              alert( "Your message could not be sent, please try again."); 
              });
    },    
});

});

在表单.js文件中,在onSubmit功能下,当用户单击"提交"按钮时.js我必须隐藏在AddButtonEntryPoint中创建的对话框。

在窗体中.js必须添加一个将引用 Dialog 实例的属性

return declare( "mypackage.MyForm", Form, {
    myDialog: null, 
    // etc
}

然后在 AddButtonEntryPoint 中,您可以在初始化 w 时设置此属性,如果将其放在以下位置:

        var d = new Dialog({
            id: 'FormDialog',
            title: "Bridge Form",
            style: "width: 270px; height: 270px;",
            content: w,
            onHide: function() {
                // To prevent destroying the dialog before the animation ends
                setTimeout(lang.hitch(this, 'destroyRecursive'), 0);
            }
        });
        var w = new Form({
            myDialog: d
        });

或者您可以保持原样并在以后调用w.set("myDialog", d); - 但在这种情况下,postCreate 中需要对话框的任何代码都不会运行。

希望这有帮助!

最新更新