EXTJS :TreePanel 单击以更改设置项

发布于 2024-11-10 15:33:54 字数 1616 浏览 2 评论 0原文

大家好 我是 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
};

我的树节点上的“监听器”:

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

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

非常感谢各位朋友的帮助!

Hi everybody
I'm a beggining with extjs and I have issue with change / set a item to a layout when i click on one of my node .

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

My "listener" on my 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 

});

My item for test :

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

So, my objective is to change item of my content panel when i click on a node.. !

Thanks a lot for your helps buddies !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

负佳期 2024-11-17 15:33:54

尝试一下并在评论中告诉我:

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

try that and tell me in the comments:

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

And in your event, based on 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'));
    }
});

By the way, in the code you provided, there is an error in the listener, it misses a } for closing the if!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文