0

大家好,我是 extjs 的初学者,当我单击我的一个节点时,我遇到了将项目更改/设置为布局的问题。

这是我的内容面板:

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
};

我的树节点上的“听众”:

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'
    }   }]
});

因此,我的目标是在单击节点时更改内容面板的项目..!

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

4

1 回答 1

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 的 }!

于 2011-05-30T16:09:42.027 回答