EXTJS:TreePanel单击以设置项目更改

时间:2011-05-30 15:36:54

标签: extjs treepanel

大家好 我正在开始使用extjs,当我点击我的一个节点时,我有更改/设置项目到布局的问题。

这里是我的contentPanel:

var contentPanel = {
    id: 'content-panel',
    region: 'center', // this is what makes this panel into a region within the containing layout
    layout: 'card',
    margins: '2 5 5 0',
    activeItem: 0,
    border: false,
    items: layoutExamples // HERE I WANT TO CHANGE DYNAMIC
};

我的treenode上的“倾听者”:

treePanel.getSelectionModel().on('select', function(selModel, record) {
    if (record.get('leaf')) {
        //Ext.getCmp('content-panel').layout.setActiveItem(record.getId() + '-panel'); <== It's work.
        Ext.getCmp('content-panel').setActive(formPanel); // HERE I TRY TO CHANGE ITEM ON CLICK AND SET FORMPANEL 

});

我的测试项目:

var formPanel = Ext.create('Ext.form.Panel', {
    frame: true,
    title: 'Form Fields',
    width: 340,
    bodyPadding: 5,

    fieldDefaults: {
        labelAlign: 'left',
        labelWidth: 90,
        anchor: '100%'
    },

    items: [{
        xtype: 'textfield',
        name: 'textfield1',
        fieldLabel: 'Text field',
        value: 'Text field value'
    }, {
        xtype: 'textfield',
        name: 'password1',
        inputType: 'password',
        fieldLabel: 'Password field'
    }, {
        xtype: 'filefield',
        name: 'file1',
        fieldLabel: 'File upload'
    }, {
        xtype: 'textareafield',
        name: 'textarea1',
        fieldLabel: 'TextArea',
        value: 'Textarea value'
    }   }]
});

所以,我的目标是在点击某个节点时更改我的内容面板的项目..!

非常感谢您的帮助伙伴们!

1 个答案:

答案 0 :(得分:2)

尝试并在评论中告诉我:

var formPanel = Ext.create('Ext.form.Panel',
    {
        'id': 'form-panel-1', // or what you want to give
        // and all the properties you already defined
    }
);

在您的活动中,基于http://docs.sencha.com/ext-js/4-0/#/api/Ext.layout.container.Card-method-setActiveItem

treePanel.getSelectionModel().on('select', function(selModel, record) {
    if (record.get('leaf')) {
        Ext.getCmp('content-panel').getLayout().setActiveItem(Ext.getCmp('form-panel-1'));
    }
});

顺便说一下,在你提供的代码中,监听器中有一个错误,它错过了}来关闭if!