论坛首页 Web前端技术论坛

extjs 5 问题,使用TreeStore with proxy方式,只能异步加载,ext官网也有错么

浏览 4575 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2014-11-26   最后修改:2014-11-26
EXT
大家好,参考官网:

http://docs.sencha.com/extjs/5.0/components/trees.html#Loading_the_Entire_Tree

按着例子,一步步做。

目的是 使用TreeStore with proxy方式 一次性 load 所有节点数据。

结果一预览就死循环了。

发现不断的去后台请求数据。

按这个文章说明,应该是一次性加载所有数据的。结果在展开时还是会去后台请求数据。

难道是我错了?

我使用的是 extjs 5.0.1 GPL 版本。

还请各位帮忙看一下,非常需要帮助。

TreeStore代码:

Ext.define('publicweb.store.MenuTreeStore', {
    extend: 'Ext.data.TreeStore',

    requires: [
        'publicweb.model.TreeMenuModel',
        'Ext.data.proxy.Ajax',
        'Ext.data.reader.Json'
    ],

    constructor: function(cfg) {
        var me = this;
        cfg = cfg || {};
        me.callParent([Ext.apply({
            storeId: 'MenuTreeStore',
            autoLoad: false,
            model: 'publicweb.model.TreeMenuModel',
            root: {
                name: 'menu-1-1-1',
                expanded: true
            },
            proxy: {
                type: 'ajax',
                url: 'menu.json',
                reader: {
                    type: 'json',
                    rootProperty: 'items'
                }
            }
        }, cfg)]);
    }
});


MODEL 代码:

Ext.define('publicweb.model.TreeMenuModel', {
    extend: 'Ext.data.Model',

    requires: [
        'Ext.data.field.Integer',
        'Ext.data.field.String'
    ],

    fields: [
        {
            type: 'int',
            name: 'id'
        },
        {
            type: 'string',
            name: 'name'
        }
    ]
});


TreePanel代码:

               {
                    xtype: 'treepanel',
                    store: 'MenuTreeStore',
                    viewConfig: {

                    },
                    columns: [
                        {
                            xtype: 'treecolumn',
                            dataIndex: 'name',
                            text: 'MyTreeColumn',
                            flex: 1
                        }
                    ]
                }


menu.json 代码:

{
    "success": true,
    "items": [
        {
            "id": 1,
            "name": "Phil",
            "leaf": true
        },
        {
            "id": 2,
            "name": "Nico",
            "expanded": true,
            "children": [
                {
                    "id": 3,
                    "name": "Mitchell",
                    "leaf": true
                }
            ]
        },
        {
            "id": 4,
            "name": "Sue",
            "loaded": true
        }
    ]
}
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics