我有一个编辑器网格面板(在表单内),它正在添加/删除美元金额的发票行项目。网格中的行项目金额被添加到网格外部但在表单内部的“到期金额”字段中。“到期金额”字段中可能有来自其他地方(不是网格)的金额。我可以在网格中的“到期金额”字段中添加和减去几个金额。但是,当我按两次“提交”按钮时(应该只有一次),它会将“应付金额”清除为零。如何确保提交按钮在意外按下两次时不会清除“到期金额”字段?我的代码应该改变什么?谢谢您的帮助。
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
}