Uco__ 2015-02-11 02:06 采纳率: 0%
浏览 1869

ExtJS使用本地JSON建树,重复加载

初学Extjs,建树时使用了本地的JSON文件,但出现重复的问题,如图
图片说明

json如下:

 {
    "success": true,
    "deps": [
        {
            "id": 1,
            "text": "Class 1",
            "leaf": false,
            "children": [
                {
                    "id": 2,
                    "text": "Class 1.1",
                    "leaf": true,
                    "children": []
                },
                {
                    "id": 3,
                    "text": "Class 1.2",
                    "leaf": true,
                    "children": []
                }
            ]
        },
        {
            "id": 4,
            "text": "Class 2",
            "leaf": false,
            "children": [
                {
                    "id": 5,
                    "text": "Class 2.1",
                    "leaf": true,
                    "children": []
                }
            ]
        }
    ]
}

model如下:

 Ext.define('App.model.Dep', {

    extend: 'Ext.data.Model',

    idProperty: 'depmodel',

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

});

store:

 Ext.define('App.store.DepTree', {

    extend: 'Ext.data.TreeStore',

    alias: 'store.deptree',

    model: 'App.model.Dep',

    autoLoad: false,

    root: {
        id: 0,
        text: 'root',
        leaf: false,
        expanded: true
    },

    proxy: {
        type: 'ajax',
        url: 'data/dep.json',
        reader: {
            type: 'json',
            rootProperty: 'deps',
            successProperty: 'success'
        }

    },

    listeners: {
        beforeload: function (store, operation, opts) {
            //阻止加载
            if (!store._can_load_) {
                return false;
            }
            return true;
        }
    }

});

treepanel:

 Ext.define('App.view.dep.DepTree', {

    extend: 'Ext.tree.Panel',

    alias: 'widget.deptree',

    uses: [
        'App.store.DepTree'
    ],

    title: '部门',

    glyph: 0xf0c9,

    rootVisible: false,

    lines: true,

    viewModel: 'dep',

    listener: {
        beforeload: function () {

        }
    },

    initComponent: function () {
        var me = this;
        var store = Ext.create('App.store.DepTree');
        me.store = store;
        me.callParent();
    }

});
  • 写回答

1条回答 默认 最新

  • Go 旅城通票 2015-02-12 02:11
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据