我有一个编辑器网格面板(在表单内),它添加/删除了一定数量的发票行项目。来自网格的订单项金额将添加到网格外部的“金额到期”字段中,但在表单内。在其他地方(不是网格)的“应付金额”字段中可能有一笔金额。我可以从网格中向“应付金额”字段添加和减去多个金额。但是,当我按下“提交”按钮两次(当它应该只有一次)时,它会将“应付金额”清零。如果意外按两次,如何确保“提交”按钮未清除“应付金额”字段?我的代码应该改变什么?谢谢你的帮助。
var iLineItemTotalHold = 0;{
text: 'Submit',
tooltip:'Submit the line item',
handler: function(){
iLineItemGrid.stopEditing();
// Will this code save changes to the database?
//iLineItemGrid.getStore().commitChanges();
iLineItemStore.commitChanges();
// What I want done here is when the amount field in the grid is saved it
// updates the 'Amount Due' field (outside of the grid) in the form.
//Does this code update the Amount Due field in the form?
var iAmountTotalForLineItems = 0;
var iAmountInDueField = Ext.getCmp('iAmountDue').value;
var tempTotal = 0;
var result = 0;
iLineItemStore.each(function(addAmount){
iAmountTotalForLineItems += addAmount.get('i_line_item_amt');
});
alert('1 iAmountInDueField: ' + iAmountInDueField +' iLineItemTotalHold: '+iLineItemTotalHold + ' iAmountTotalForLineItems: '+ iAmountTotalForLineItems);
if (iLineItemTotalHold > iAmountTotalForLineItems ){
alert ('if');
tempTotal = iLineItemTotalHold - iAmountTotalForLineItems;
result = iAmountInDueField - tempTotal;
alert('two: '+result+' = '+iAmountInDueField+' + '+tempTotal );
}
else if (iLineItemTotalHold < iAmountTotalForLineItems ){
alert ('if2');
tempTotal = iAmountTotalForLineItems - iLineItemTotalHold;
result = iAmountInDueField + tempTotal;
alert('3: '+result+' = '+iAmountInDueField+' - '+tempTotal );
}
iLineItemTotalHold = iAmountTotalForLineItems;
Ext.getCmp('iAmountDue').setValue(result);
},
scope:this
}
答案 0 :(得分:0)
在handler
功能结束时添加:
this.setDisabled(true);
禁用按钮并防止再次点击。
然后向网格的edit
事件添加一个侦听器,以便在编辑完成时再次启用该按钮。类似的东西:
Ext.create('Ext.grid.Panel', {
// your other grid configs
listeners: {
edit: function(editor, edit) {
var form = edit.grid.up('form'),
button = form.down('button[text=Submit]');
// enable the button after the grid is edited
button.setDisabled(false);
}
}
});
然后我还建议您将按钮设为disabled: true
。首次编辑网格时,将使用edit
处理程序启用该按钮。