4

新版本的 ExtJS 可以让你的 chrome 不稳定(或者是我的代码?)!让我解释一下我的情况。

我正在研究 ExtJS 4.0 的新 MVC 架构。我有一个树面板显示我的应用程序菜单或导航。根据架构,我尝试将树面板拆分为控制器、视图和单独的存储。

这是我的看法:

 Ext.define('CRM.view.menu.View', {
    alias: 'widget.menutree',
    extend: 'Ext.tree.Panel',

    initComponent: function() {

        console.log('initComponent of View...');

        Ext.apply(this, {
            title: 'Simple Tree',                       
            width: 200,             
            store: 'MainMenu',
            rootVisible: false
        });

        this.callParent(arguments);
    }
});

我的树店:

 Ext.define('CRM.store.MainMenu', {
    extend: 'Ext.data.TreeStore', 

    constructor: function() {

        console.log('Constructor of MainMenu TreeStore');

        config = Ext.apply(this,{
            proxy: {
                type: 'ajax',
                url: 'data/menu.json'
            },root: {
                text: 'Menu',
                id: 'src',
                expanded: true
            }
        });

        this.callParent(arguments);

    }
}); 

在我的控制器中,我也提供了我的商店信息。这是我的控制器配置的一部分:

Ext.define('CRM.controller.MainMenu',{
    extend: 'Ext.app.Controller',
    stores: ['MainMenu'],   
    refs: [
        {ref:'menu',selector: 'menutree'},
        {ref:'cp',selector: 'centerpane'}
    ],
        .
        .
        .

在初始执行时,我收到以下错误:

对象 MainMenu 没有方法“getRootNode”

但是现在,我得到了更奇怪的错误:chrome 只是无法显示应用程序 注意 chrome 在树存储的构造函数中停止执行。

同时,在firefox中:firefox 执行得更好 Firefox执行得更好,但是没有应用程序渲染!

经过一些尝试和错误..我确实找到了一种让我的应用程序运行的方法..那就是避免使用我的商店并直接提供商店信息,如下所示:

 Ext.define('CRM.view.menu.View', {
    alias: 'widget.menutree',
    extend: 'Ext.tree.Panel',

    initComponent: function() {

        console.log('initComponent of View...');

        Ext.apply(this, {
            title: 'Simple Tree',                       
            width: 200,             
            store: {
                proxy: {
                    type: 'ajax',
                    url: 'data/menu.json'
                },root: {
                    text: 'Menu',
                    id: 'src',
                    expanded: true
                }
            },
            rootVisible: false
        });

        this.callParent(arguments);
    }
});

现在应用程序执行完全没有问题!

有人尝试使用 MVC 架构创建树面板吗?我不知道如何解决这个问题!

4

1 回答 1

3

看起来这是一个已知问题!!!引用ExtJS 论坛

“Ext.tree.Panel”的父类在“initComponent”方法中的store manager中寻找store,但是“Ext.tree.Panel”之前尝试使用它。

因此,一种方法是将您的商店编码到您的树中,另一种方法是在 initComponent 方法中重新分配商店。这是代码:

initComponent: function(){
  this.store = Ext.data.StoreManager.lookup(this.store);
  this.callParent(arguments);
} 
于 2011-05-12T07:18:41.030 回答