我已经在AddButtonEntryPoint.js文件中创建了对话框,并且我想在单击Submit按钮之后访问Form.js文件中的该变量以隐藏对话框,所以,我该怎么调用。
这是我写的代码
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函数下,当用户单击“提交”按钮时,我必须隐藏在AddButtonEntryPoint.js中创建的对话框。
答案 0 :(得分:0)
在Form.js中,您必须添加一个引用Dialog实例的属性
return declare( "mypackage.MyForm", Form, {
myDialog: null,
// etc
}
然后在AddButtonEntryPoint中,如果将w放在后面,则可以在初始化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中任何要求对话框的代码都不会运行。
希望这会有所帮助!