2016-12-29 27 views
0
var enableBtn = Ext.create('Ext.button.Button', { 
     text : 'Edit Label', 
     disabled: false, 
     scope : this, 
     handler : function() { 
      //disable the enable button and enable the disable button 
      //enableBtn.disable(); 
      //disableBtn.enable(); 

     //enable the toolbar 
     //toolbar.enable(); 
     tFieldPage.setText('7'); 
    } 
}); 

var tFieldPage = new Ext.form.Label({ 
      text: 1 
     }); 

var toolbar = Ext.create('Ext.toolbar.Toolbar', { 
    //renderTo: document.body, 
    //width : 400, 
    enableOverflow: true, 
    margin : '5 0 0 0', 
    items : [enableBtn, tFieldPage] 
}); 


Ext.create('Ext.window.Window', { 
     title: 'Standard', 
     closable: false, 
     height:250, 
     width: 500, 
     bodyStyle: 'padding:10px', 
     //contentEl: 'content', 
     scrollable: true, 
     tbar: toolbar 
    }).show(); 

我使用的是ExtJS 5.0.1,我發現當您縮小窗口並且標籤'1'進入溢出菜單時,當我按下按鈕更新標籤,它不會更新。但是,當我展開工具欄時,標籤會再次更新。經過檢查,我意識到當溢出時,會自動創建另一個標籤。如何獲取我創建的原始組件,以便在溢出菜單中更新克隆的組件?ExtJS 5工具欄中的標籤在溢出時未更新

我測試如上所述使用煎茶撥弄和相同的錯誤代碼顯示爲好。任何建議或者這是一個框架問題?

編輯:我的小提琴鏈接:https://fiddle.sencha.com/#view/editor&fiddle/1nc7

感謝。

+0

會更好。 – abeyaz

+0

嗨,我已經添加了小提琴鏈接。 – user1679887

+0

看起來像是extjs5中的一個bug。如果你在extjs6小提琴上嘗試它,你會發現它正在工作。你可以做的是要麼開始使用extjs6這是非常相似的V5,或者你可以比較兩個版本的'Ext.layout.container.boxOverflow.Menu'類的源代碼,並查看您的問題缺少/越野車的一部分。然後你可以很容易地覆蓋它。 – abeyaz

回答

0

標籤組件重新創建私人Ext.layout.container.boxOverflow.Menu(兩次 - 我不找出原因)。重新創建標籤使用原始標籤的initialConfig。所以這是可能的:

  • 得到原來的標籤
    • 設置按鈕處理範圍爲標籤
    • 獲取工具欄,然後標籤:comp.up('toolbar').down('label'))
  • 改變原來的標籤文字:setText()
  • 設置文本重新標籤變化initialConfig

    var tFieldPage = new Ext.form.Label({ 
        text: 1 
    }); 
    
    var enableBtn = Ext.create('Ext.button.Button', { 
        text : 'Edit Label', 
        disabled: false, 
        scope : tFieldPage,//bind scope 
        handler : function(comp, event) { 
        console.log('btnhandler scope: ',comp.id); 
        console.log('btnhandler scope.owner: ',comp.ownerCt.id); 
        if(comp.up('button')){ 
         console.log('original label: ', comp.up('toolbar').down('label')); 
         console.log('recreated label: ', comp.nextSibling()); 
        } 
        this.setText('7'); 
        this.initialConfig.text = 7; 
        } 
    }); 
    

這裏是如果您共享小提琴https://fiddle.sencha.com/得到這個幫助fiddle