如何在dojo工具包的Current JS文件中使用在另一个JS文件中创建的Dialog变量

问题描述 投票:1回答:1

我在AddButtonEntryPoint.js文件中创建了Dialog,我想在Form.js文件中访问该变量,以便在单击Submit按钮后隐藏对话框所以,我该如何调用。

这是我写的代码

AddButtonEntryPoint.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();
        };          

Form.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."); 
              });
    },    
});

} );

在form.js文件中,在onSubmit函数下,当用户单击Submit按钮时,我必须隐藏在AddButtonEntryPoint.js中创建的对话框。

dojo
1个回答
0
投票

在Form.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中需要对话框的任何代码都不会运行。

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.