ExtJS4:将参数/属性从 Treestore 传递到控制器

发布于 2025-01-01 04:31:02 字数 1980 浏览 3 评论 0原文

我正在使用一个没有代理的简单 TreeStore 来构建我的菜单。这是一个简单的示例:

Store:

Ext.define('LT.store.MnuApplication', {
    extend: 'Ext.data.TreeStore',
    root: {
        expanded: true,
        children: [{
            text: "Lists", 
            expanded: true, 
            children: [{
                text: "Countries", 
                leaf: true,
            }]
        }]
    }
});

在控制器中,我为“click”事件添加了一个监听器:

Controller:

init: function() {

        this.control({

            /**
             * Catch the treepanels in the menu accordion
             */
            'menu-main treepanel': {

                itemclick: function (view, record, item, index, event){

                    var clickedMnuNode = record;
                    var tabPanel = this.getTabPanel();                   

                    // Open tab only if the menu node is a leaf node
                    if (clickedMnuNode.isLeaf()) {
                        tabPanel.add({
                            xtype: clickedMnuNode.raw.loadTabComponent
                        }).show();
                    }
                }
            }
        });

        this.callParent();

    }

现在解决我的问题:我想要在 TreeStore 中定义哪些操作应该由控制器完成 - 特别是应该加载哪个组件。

例如,我希望 TreeStore 看起来像这样:

Ext.define('LT.store.MnuApplication', {
    extend: 'Ext.data.TreeStore',
    root: {
        expanded: true,
        children: [{
            text: "Lists", 
            expanded: true, 
            children: [{
                text: "Countries", 
                leaf: true,
                loadComponent: 'country-list',
                loadTarget: 'tabPanel'
            }]
        }]
    }
});

如您所见,我向 Tree Leaf 添加了两个新参数。现在我可以通过记录的“RAW”方法访问这些数据集。但这并不是一个很好的解决方案 - 不是吗?

那么有人对我有想法吗,如何将附加参数(如“loadComponent”或“loadTaget”)从我的 TreeStore 传递到控制器?

提前致谢&干杯, 迈克尔

I´m using a simple TreeStore without proxies for building my Menu. Here is a simple Example:

Store:

Ext.define('LT.store.MnuApplication', {
    extend: 'Ext.data.TreeStore',
    root: {
        expanded: true,
        children: [{
            text: "Lists", 
            expanded: true, 
            children: [{
                text: "Countries", 
                leaf: true,
            }]
        }]
    }
});

In the controller I´ve added a listener to the "click" event:

Controller:

init: function() {

        this.control({

            /**
             * Catch the treepanels in the menu accordion
             */
            'menu-main treepanel': {

                itemclick: function (view, record, item, index, event){

                    var clickedMnuNode = record;
                    var tabPanel = this.getTabPanel();                   

                    // Open tab only if the menu node is a leaf node
                    if (clickedMnuNode.isLeaf()) {
                        tabPanel.add({
                            xtype: clickedMnuNode.raw.loadTabComponent
                        }).show();
                    }
                }
            }
        });

        this.callParent();

    }

And now to my problem with this solution: I want to define in the TreeStore, which actions should be done by the controller - especially which component should be loaded.

For example I would like that the TreeStore looks like this:

Ext.define('LT.store.MnuApplication', {
    extend: 'Ext.data.TreeStore',
    root: {
        expanded: true,
        children: [{
            text: "Lists", 
            expanded: true, 
            children: [{
                text: "Countries", 
                leaf: true,
                loadComponent: 'country-list',
                loadTarget: 'tabPanel'
            }]
        }]
    }
});

As you can see I´ve added two new parameters to the Tree Leaf. Now I cann access those datasets via the "RAW" method of the record. But that´s not really a nice solution - isn´t it?

So has anyone an idea for me, how to pass additional parameters (like "loadComponent" or "loadTaget") from my TreeStore to the controller?

Thanks in advance & cheers,
Michael

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

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

发布评论

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

评论(1

2025-01-08 04:31:02

过去,我使用自定义参数创建了类似的树,并为 TreeStore 使用了自定义模型。因为默认情况下你的节点只有 NodeInterface 的属性。像这样的事情:

Ext.define('TreeConfig.model.Config', {
    extend: 'Ext.data.Model',
    fields: ['properties', 'id', 'text', 'guid'],
    proxy: {
        type: 'ajax',
        url: rootConfigURL,
        actionMethods: 'POST',
        reader: {
            type: 'json'            
        }
    }
});


Ext.define('TreeConfig.store.CurrentConfig', {
    extend: 'Ext.data.TreeStore',
    model: 'TreeConfig.model.Config',
    requires: 'TreeConfig.model.Config',    
    root: {
        text: 'Config root',
        expanded: true,
        properties: []        
    }
});

In the past I created similar tree with my custom parameters and I used a custom model for my TreeStore. Because by default your node, just has properties of NodeInterface. Something like this:

Ext.define('TreeConfig.model.Config', {
    extend: 'Ext.data.Model',
    fields: ['properties', 'id', 'text', 'guid'],
    proxy: {
        type: 'ajax',
        url: rootConfigURL,
        actionMethods: 'POST',
        reader: {
            type: 'json'            
        }
    }
});


Ext.define('TreeConfig.store.CurrentConfig', {
    extend: 'Ext.data.TreeStore',
    model: 'TreeConfig.model.Config',
    requires: 'TreeConfig.model.Config',    
    root: {
        text: 'Config root',
        expanded: true,
        properties: []        
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文