在 DOJO 确认对话框中动态设置 onExecute 回调函数
Dynamically Set onExecute callback function in DOJO Confirm Dialog
我的 jsp 中有两个 html 按钮。一个是添加,另一个是删除。
现在,如果单击其中一个按钮,则会显示一个 dojo 确认对话框。单击对话框中的 'Ok' 将执行添加或删除功能。这个 Dojo 对话框出现在父 jsp 页面之一中,该页面将被其他 jsp 页面重复使用,其中存在添加或删除功能。根据 Add/Remove 按钮单击确认消息也需要更改。前任。对于添加,消息应为 'Do you want to Add' ,对于删除消息应为 'Do you want to Remove'。我可以在 DOJO Cinfirm 对话框中动态设置消息,但无法设置 onExecute 回调函数,即。当在对话框中单击“确定”时。下面是代码。
注意:我正在使用 DOJO 1.10 库
确认对话框代码:
require(["dijit/ConfirmDialog", "dojo/domReady!"], function(ConfirmDialog){
myDialog = new ConfirmDialog({
title: "GCLDW - Confirm Dialog",
content: "",
style: "width: 300px;",
onExecute:function(){
removeCustomer();
}
});
});
HTML 按钮代码:
<button type="button" id="removeCustomerButton"
onclick="myDialog.set('content', 'Do you want to remove the selected item ?<br><br>');myDialog.show();">
<SPAN class=grey><EM><s:message
code="customer.removeCustomer" text="" /></EM>
</SPAN>
</button>
<button type="button" id="addCustomerButton"
onclick="myDialog.set('content', 'Do you want to Add the selected item ?<br><br>');myDialog.show();">
<SPAN class=grey><EM><s:message
code="customer.addCustomer" text=""/></EM>
</SPAN>
</button>
现在如何根据按钮点击设置 onExecute 回调函数,要么是 addCustomer() 要么是 removeCustomer() ,无论哪个页面使用这个对话框都会有自己的这两个方法的实现。
只需设置 onExecute 块 - 以相同的方式设置内容。
还有一个建议是- 将 JS 代码与 HTML 分开。
这里是解决方法-
HTML代码-
<button type="button" id="removeCustomerButton">
<SPAN class=grey><EM>Remove</EM></SPAN>
</button>
<button type="button" id="addCustomerButton">
<SPAN class=grey><EM>Add</EM></SPAN>
</button>
&道场-
require(["dijit/ConfirmDialog", "dojo/domReady!"],
function(ConfirmDialog){
var myDialog = new ConfirmDialog({
title: "GCLDW - Confirm Dialog",
content: "",
style: "width: 300px;"
});
dojo.query('#removeCustomerButton').onclick( function() {
myDialog.set('content', 'Do you want to remove the selected item ?<br><br>');
myDialog.set('onExecute', function(){removeCustomer()} ); // cant call it directly- must wrap within a function
myDialog.show();
});
dojo.query('#addCustomerButton').onclick( function() {
myDialog.set('content', 'Do you want to Add the selected item ?<br><br>');
myDialog.set('onExecute', function(){addCustomer()} ); // cant call it directly- must wrap within a function
myDialog.show();
});
});
function removeCustomer(){
console.log("removeCustomer called on execute");
}
function addCustomer(){
console.log("addCustomer called on execute");
}
在 /dojo-release-1.10.4-src/dijit/_DialogMixin.js 中,评论状态:
execute: function(/*Object*/ /*===== formContents =====*/){
// summary:
// Callback when the user hits the submit button.
// Override this method to handle Dialog execution.
我像这样实现了 ConfirmDialog:
var confirmDialog = new ConfirmDialog({
title: core.confirm
});
confirmDialog.startup();
function confirmAction(text, callbackFn) {
confirmDialog.set("execute", callbackFn);
confirmDialog.set("content", text);
confirmDialog.show();
}
并称其为:
lib.confirmAction(core.areyousure, function () {
markedForDeletion.forEach(function (node) {
// Do deletion
});
});
我的 jsp 中有两个 html 按钮。一个是添加,另一个是删除。 现在,如果单击其中一个按钮,则会显示一个 dojo 确认对话框。单击对话框中的 'Ok' 将执行添加或删除功能。这个 Dojo 对话框出现在父 jsp 页面之一中,该页面将被其他 jsp 页面重复使用,其中存在添加或删除功能。根据 Add/Remove 按钮单击确认消息也需要更改。前任。对于添加,消息应为 'Do you want to Add' ,对于删除消息应为 'Do you want to Remove'。我可以在 DOJO Cinfirm 对话框中动态设置消息,但无法设置 onExecute 回调函数,即。当在对话框中单击“确定”时。下面是代码。
注意:我正在使用 DOJO 1.10 库
确认对话框代码:
require(["dijit/ConfirmDialog", "dojo/domReady!"], function(ConfirmDialog){
myDialog = new ConfirmDialog({
title: "GCLDW - Confirm Dialog",
content: "",
style: "width: 300px;",
onExecute:function(){
removeCustomer();
}
});
});
HTML 按钮代码:
<button type="button" id="removeCustomerButton"
onclick="myDialog.set('content', 'Do you want to remove the selected item ?<br><br>');myDialog.show();">
<SPAN class=grey><EM><s:message
code="customer.removeCustomer" text="" /></EM>
</SPAN>
</button>
<button type="button" id="addCustomerButton"
onclick="myDialog.set('content', 'Do you want to Add the selected item ?<br><br>');myDialog.show();">
<SPAN class=grey><EM><s:message
code="customer.addCustomer" text=""/></EM>
</SPAN>
</button>
现在如何根据按钮点击设置 onExecute 回调函数,要么是 addCustomer() 要么是 removeCustomer() ,无论哪个页面使用这个对话框都会有自己的这两个方法的实现。
只需设置 onExecute 块 - 以相同的方式设置内容。
还有一个建议是- 将 JS 代码与 HTML 分开。
这里是解决方法-
HTML代码-
<button type="button" id="removeCustomerButton">
<SPAN class=grey><EM>Remove</EM></SPAN>
</button>
<button type="button" id="addCustomerButton">
<SPAN class=grey><EM>Add</EM></SPAN>
</button>
&道场-
require(["dijit/ConfirmDialog", "dojo/domReady!"],
function(ConfirmDialog){
var myDialog = new ConfirmDialog({
title: "GCLDW - Confirm Dialog",
content: "",
style: "width: 300px;"
});
dojo.query('#removeCustomerButton').onclick( function() {
myDialog.set('content', 'Do you want to remove the selected item ?<br><br>');
myDialog.set('onExecute', function(){removeCustomer()} ); // cant call it directly- must wrap within a function
myDialog.show();
});
dojo.query('#addCustomerButton').onclick( function() {
myDialog.set('content', 'Do you want to Add the selected item ?<br><br>');
myDialog.set('onExecute', function(){addCustomer()} ); // cant call it directly- must wrap within a function
myDialog.show();
});
});
function removeCustomer(){
console.log("removeCustomer called on execute");
}
function addCustomer(){
console.log("addCustomer called on execute");
}
在 /dojo-release-1.10.4-src/dijit/_DialogMixin.js 中,评论状态:
execute: function(/*Object*/ /*===== formContents =====*/){
// summary:
// Callback when the user hits the submit button.
// Override this method to handle Dialog execution.
我像这样实现了 ConfirmDialog:
var confirmDialog = new ConfirmDialog({
title: core.confirm
});
confirmDialog.startup();
function confirmAction(text, callbackFn) {
confirmDialog.set("execute", callbackFn);
confirmDialog.set("content", text);
confirmDialog.show();
}
并称其为:
lib.confirmAction(core.areyousure, function () {
markedForDeletion.forEach(function (node) {
// Do deletion
});
});