[英]dojox/form/Manager onSubmit fires more than once
我已經聲明了一個基於dgrid / OnDemandGrid的類。 該類可以顯示選定的記錄,以便使用dojox / form / Manager編輯,該記錄已放置在dijit / Dialog中。 當編輯第一個記錄時,一切正常,但是后續的提交似乎會累積並重復引發事件,盡管put方法似乎每次提交僅被調用一次。
請在以下網址查看Firebug輸出: http://speedyshare.com/hQBuP/submitRecord.png (只需單擊頂部的文件名)
編輯和提交方法類似於下面的代碼。 歡迎提出任何關於我的代碼有問題的建議。
提前致謝。
editRecord: function() {
this.editMode = "edit";
var rec = this.store.get(currentRowId);
var form = registry.byId(this.editFormId);
var dialog = registry.byId(this.dialogId);
form.reset();
form.setFormValues(rec);
form.on("submit", lang.hitch(this, this.submitRecord));
var cancelButton = registry.byId(this.cancelButtonId);
dialog.show().then(function(){cancelButton.focus();});
},
submitRecord: function(event) {
// Testing counter
if(!this.counter)
this.counter = 1;
else
this.counter++;
console.log("Submit event: " + this.counter);
// Get form, dialog and retrieve record
var form = registry.byId(this.editFormId);
var dialog = registry.byId(this.dialogId);
// Check validity
if(!form.validate()) {
return false;
}
var rec = form.gatherFormValues();
// Put record in store
this.store.put(rec).then( /*..... pop up status or error toaster (code omitted)..*/ );
// Dismiss dialog
form.reset();
dialog.hide();
// Stop submit event
event.stopPropagation();
event.preventDefault();
return false;
}
每次調用editRecord
,您都將附加一個submit
事件偵聽器,大概是每次您顯示對話框時,都將附加一個submit
事件偵聽器。 您真的只想附加一次該偵聽器。 由於您永遠都不會刪除並添加它,因此editRecord
是在每次調用editRecord
之后,使同一函數在下一次提交時觸發n + 1次。 而是在創建表單后,完全將一次提交事件處理程序連接起來。
如果我不得不猜測, store.put
只被調用一次的原因是因為您隨后重置了表單,所以后續對submitRecord
重復調用將使validate
調用失敗,並在put
調用之前退出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.