【问题标题】:extjs loading tree from json file using MVCextjs 使用 MVC 从 json 文件加载树
【发布时间】:2012-02-27 21:35:06
【问题描述】:

在这里,我遇到了一个奇怪的问题,当我从 json 文件加载树时,它进入一个循环并按如下方式显示树(在一个连续循环中)

-A
  -A
    -A
      -A

我的json

{
    "success": true,
    "results": [
        { "text": "number 1", "leaf": true },
        { "text": "number 2", "leaf": true },
        { "text": "number 3", "leaf": true },
        { "text": "number 4", "expanded": true, "children":[
            { "text": "number 4.1", "leaf": true },
            { "text": "number 4.2", "leaf": true },
            { "text": "number 4.3", "leaf": true }
        ]},
        { "text": "number 5", "leaf": true }
    ]
}

我的模型

Ext.define('App.model.TreeModel', {
    extend:'Ext.data.Model',
    fields: [
             { name: 'text', type: 'string'}
         ],

        proxy:{
            type:'ajax',
            url: 'data/tree.json',
            reader:{
                type:'json',
                root:'results'
            }
        }
    });

商店

Ext.define('App.store.MyTreeStore', {
    extend: 'Ext.data.TreeStore',
    requires: 'App.model.TreeModel',
    model:'App.model.TreeModel',
});

查看

Ext.define('App.view.MeetingTree', {
    extend:'Ext.tree.Panel',
    title:'Simple Tree',
    store:'MyTreeStore',
    alias:'widget.meetingtree',
    rootVisible:false,
    height:200
});

我的初始化文件

Ext.application({
    name: 'App', 
    autoCreateViewport: true,

    models: ['TreeModel'],    
    stores: ['MyTreeStore'],

    launch: function() {

    }
});

不知道为什么它会循环播放.. 有人知道吗?

提前致谢

【问题讨论】:

    标签: json model-view-controller extjs tree store


    【解决方案1】:

    终于找到解决办法了

    删除线

    root:'results'
    

    来自模型

    并为 json 加星标

    { 
    text: '.',
    children: [{
    

    完整的json

    { 
    text: '.',
    children: [{
        text:'Basic Ext Layouts',
        expanded: true,
        children:[{
            text:'Absolute',
            id:'absolute',
            leaf:true
        },{
            text:'Accordion',
            id:'accordion',
            leaf:true
        },{
            text:'Anchor',
            id:'anchor',
            leaf:true
        },{
            text:'Border',
            id:'border',
            leaf:true
        },{
            text:'Card (TabPanel)',
            id:'card-tabs',
            leaf:true
        },{
            text:'Card (Wizard)',
            id:'card-wizard',
            leaf:true
        },{
            text:'Column',
            id:'column',
            leaf:true
        },{
            text:'Fit',
            id:'fit',
            leaf:true
        },{
            text:'Table',
            id:'table',
            leaf:true
        },{
            text:'vBox',
            id:'vbox',
            leaf:true
        },{
            text:'hBox',
            id:'hbox',
            leaf:true
        }]
    },{
        text:'Custom Layouts',
        children:[{
            text:'Center',
            id:'center',
            leaf:true
        }]
    },{
        text:'Combination Examples',
        children:[{
            text:'Absolute Layout Form',
            id:'abs-form',
            leaf:true
        },{
            text:'Tabs with Nested Layouts',
            id:'tabs-nested-layouts',
            leaf:true
        }]
    }]
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-19
      • 2012-06-10
      • 2013-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 2020-02-28
      相关资源
      最近更新 更多