0

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

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
    }
4

1 回答 1

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处理程序启用。

于 2012-08-02T17:01:27.293 回答