2015-11-07 46 views
0

我一直在尋找這麼久,我找不到具體的答案。比方說,我有一個擴展控制面板從這樣的:如何根據初始配置設置屬性?

Ext.define('MyApp.view.admin.User',{ 
extend: 'Ext.panel.Panel', 
config: { 
    canAdd: false, 
    canDelete: false, 
    canEdit: false 
}, 
constructor: function(config){ 
    this.initConfig(config); 
    this.callParent(arguments); 
}, 
xtype: 'user', 
requires: [ 
    'MyApp.view.admin.UsersGrid', 
    'MyApp.view.admin.UserModel', 
    'MyApp.view.admin.UserController', 
    'MyApp.model.User' 
], 
viewModel: { 
    type: 'user' 
}, 
controller: 'user', 
frame: true, 
layout: { 
    type: 'vbox', 
    align: 'stretch' 
}, 
items: [ 
    { 
     xtype: 'users-grid', 
     flex: 1 
    } 
], 
dockedItems: [ 
    { 
     xtype: 'toolbar', 
     dock: 'top', 
     items: [ 
      { 
       xtype: 'button', 
       text: 'Add', 
       glyph: MyApp.util.Glyphs.getGlyph('add'), 
       hidden: **[config.canAdd]** 
       listeners: { 
        click: 'onAdd' 
       } 
      }, 
      { 
       xtype: 'button', 
       bind: { 
        disabled: '{!usersGrid.selection}' 
       }, 
       text: 'Edit', 
       hidden: **[config.canEdit]** 
       hidden: this.setElementConfiguration, 
       glyph: Mofeg.util.Glyphs.getGlyph('edit'), 
       listeners: { 
        click: 'onEdit' 
       } 
      }, 
      { 
       xtype: 'button', 
       bind: { 
        disabled: '{!usersGrid.selection}' 
       }, 
       text: 'Eliminar', 
       glyph: MyApp.util.Glyphs.getGlyph('destroy'), 
       listeners: { 
        click: 'onDelete' 
       } 
      } 
     ] 
    } 
]}); 

我想申請基於初始配置按鈕的隱藏屬性,我怎麼能做到呢?

回答

1

你可以寫一個initComponent

initComponent: function() { 
    var me = this, 
     editButton = Ext.ComponentQuery.query('button[itemId=edit]')[0], 
     canEdit = me.getCanEdit(); 

    editButton.setHidden(canEdit); 

    me.callParent(arguments); 
} 
相關問題