簡體   English   中英

如何確保在Ext.FormPanel成功提交數據之前不執行功能?

[英]How to make sure a function is not executed until Ext.FormPanel has successfully submitted its data?

我有一個Ext.FormPanel,它具有一個Save按鈕,該按鈕應該按此順序執行兩件事: (1)發布數據, (2)從調用它的位置返回頁面。

buttons: [{
        text: 'Save',
        handler: function() {
            if(panel_form.getForm().isValid()){
                panel_form.getForm().getEl().dom.action = 'backend/page/blocks/edit_positioned_post/17.html';
                panel_form.getForm().getEl().dom.method = 'POST';
                panel_form.getForm().submit(); //FIRST POST DATA
                replace_region_with_uri_content('/backend/page'); //THEN GO BACK
            } else {
                Ext.Msg.minWidth = 360;
                Ext.Msg.alert('Invalid Form', 'Some fields are invalid, please correct.');
            }
        }
    },{
        text: 'Cancel',
        handler: function(){
            replace_region_with_uri_content('/backend/page');
        }
    }]

但是實際上發生的是向后的,正如我在Firebug中看到的那樣,即它(1)返回 ,而(2)發布數據,這導致它返回到的網格不顯示更新的數據的情況

替代文字

我如何強制它僅在panel_form.getForm().submit()完成之后(即通過發送第一個函數作為第二個函數的回調replace_region_with_uri_content()來執行replace_region_with_uri_content()

您應該在表單中添加一個事件,並檢查BasicForm的actioncomplete事件-

http://dev.sencha.com/deploy/dev/docs/?class=Ext.form.BasicForm

您僅應重定向到此處,因為一旦執行此事件,您的表單應已提交。

我找到了它,您可以像這樣將“成功函數”添加到submit()的參數數組中:

    buttons: [{
            text: 'Save',
            handler: function() {
                if(panel_form.getForm().isValid()){
                    panel_form.getForm().getEl().dom.action = 'backend/page/blocks/edit_positioned_post/17.html';
                    panel_form.getForm().getEl().dom.method = 'POST';
                    panel_form.getForm().submit({
                        success : function(form, action) {
                            replace_region_with_uri_content('/backend/page');
                        }
                    })
                } else {
                    Ext.Msg.minWidth = 360;
                    Ext.Msg.alert('Invalid Form', 'Some fields are invalid, please correct.');
                }
            }
        },{
            text: 'Cancel',
            handler: function(){
                replace_region_with_uri_content('/backend/page');
            }
        }]
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM