简体   繁体   English

保存在extjs4.2中后禁用按钮

[英]Disable a button after save in extjs4.2

I am saving three tabs on a one save button, however on the click of the save button i'm trying to disable the button while saving the data in the three tabs to prevent the user from clicking several times on the save button, because i have a timeout in my function. 我在一个保存按钮上保存了三个标签,但是在单击保存按钮时,我试图禁用该按钮,同时将数据保存在三个标签中,以防止用户多次单击保存按钮,因为我我的功能超时。 Any help on how to do so? 有什么帮助吗?

Ext.onReady(function(){



    tabPanel = Ext.create('Ext.tab.Panel', {
        region: 'center',
        activeTab: 0,
        autoScroll: true,
        tbar: [{
            xtype: 'button',
            deferredRender : false, 
            handler:function(){
            save("frm_A", save);
            },    


        }],
        items: [
                {   
                    id:"panel_A",
                    html: "<iframe src= '"+A_url +"' width='100%' height='100%' id='frm_A' name='frm_A' frameborder=0 />",        
                },{
                    id:"panel_B",
                    html: "<iframe src='"+B_url+"'  width='100%' height='100%' id='frm_B' name='frm_B' frameborder=0 />",

                },{
                    id:"panel_C",
                    html: "<iframe src= '"+C_url+"' width='100%' height='100%' id='frm_C' name='frm_C' frameborder=0 />",
                }]

        });


    viewport = new Ext.Viewport({
        layout:'border',
        items:[tabPanel]
    });



    function save(record){

        var Aid = record.getField("NUMBER").getRealValue();
        var currentTab = tabPanel.getActiveTab();
              tabPanel.setActiveTab(1);
              tabPanel.setActiveTab(2);
              tabPanel.setActiveTab(0);
              tabPanel.setActiveTab(currentTab);

        var B= window.frames["frm_B"];
        var C= window.frames["frm_C"];

        setTimeout(function(){   
            try {
            B.RECORD.getField("ID").setRealValue(Aid);
            C.RECORD.getField("ID").setRealValue(Aid);
            B.RECORD.update();
            C.RECORD.update();

            parent.refreshGrid();
            parent.win.close();
        }
        catch(e){
            showError(e);
        }
        }, 4000);

    }


});

One way in your save handler is to call the button's setDisabled() method. 保存处理程序中的一种方法是调用按钮的setDisabled()方法。

Example: 例:

handler: function() {
   this.setDisabled(true);
   save("frm_A", save);
}

Then, inside your setTimeout you can setDisabled(false). 然后,在setTimeout内部,可以设置setDisabled(false)。

To be able to do that effectively you may want to consider refactoring your save handler a little bit, for example, by passing "this" as a parameter to your save function so that you can call setDisabled(false) on that parameter. 为了能够有效地做到这一点,您可能需要考虑对存储处理程序进行一些重构,例如,通过将“ this”作为参数传递给保存函数,以便可以对该参数调用setDisabled(false)。

https://docs.sencha.com/extjs/4.2.5/#!/api/Ext.button.Button-method-setDisabled https://docs.sencha.com/extjs/4.2.5/#!/api/Ext.button.Button-method-setDisabled

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM