4

我创建了一个树形面板,然后创建store

          var store = Ext.create('Ext.data.TreeStore', {
            autoload: false,
            proxy: {
                type: 'ajax',
                url: 'data.php',
                reader: {
                    type: 'json',
                    root: 'results'                 
                }
            }
          });

我的服务器打印 json 看起来像

{ "results": 
    [
    { id : '1' , text : '1', expanded: true, 
        children :[
            { id : '5' , text : '5', leaf:true},
            { id : '6' , text : '6', leaf:true}
        ]
    },
    { id : '2' , text : '2', leaf:true},
    { id : '3' , text : '3', leaf:true},
    { id : '4' , text : '4', leaf:true},
    { id : '7' , text : '7', leaf:true},
    { id : '8' , text : '8', leaf:true},
    { id : '9' , text : '9', leaf:true},
    { id : '10' , text : '10', expanded: true, 
        children :[
            { id : '11' , text : '11', leaf:true},
            { id : '12' , text : '12', leaf:true}
        ]
    }
    ]
}

但是当我运行我的代码时,我看到了萤火虫并且它总是运行GET http://localhost/example/data.php...永不停止:(

我的树加了很多倍

怎么解决 谢谢

编辑
实际上,我用别名定义了我的树形面板并将其用作xtype
但是我创建了新示例并遇到了同样的问题。这是我的js

var store = Ext.create('Ext.data.TreeStore', {
            autoload: false,
            proxy: {
                type: 'ajax',
                url: 'data.php',
                reader: {
                    type: 'json',
                    root: 'results'                 
                }
            }
        });

        Ext.create('Ext.tree.Panel', {
            title: 'Simple Tree',
            width: 200,
            height: 150,
            store: store,
            rootVisible: false,
            renderTo: Ext.getBody()
        });

这是我的data.php

echo "
{
    'success': true, 
    'variable': 100, 
    'results': 
    [
    { id : '1' , text : '1', expanded: true, 
        children :[
            { id : '5' , text : '5', leaf:true},
            { id : '6' , text : '6', leaf:true}
        ]
    },
    { id : '2' , text : '2', leaf:true},
    { id : '3' , text : '3', leaf:true},
    { id : '4' , text : '4', leaf:true},
    { id : '7' , text : '7', leaf:true},
    { id : '8' , text : '8', leaf:true},
    { id : '9' , text : '9', leaf:true},
    { id : '10' , text : '10', expanded: true, 
        children :[
            { id : '11' , text : '11', leaf:true},
            { id : '12' , text : '12', leaf:true}
        ]
    }
    ]
}";
4

3 回答 3

5

你在这里拥有的是我认为是树库中的错误的东西。当您将阅读器更改为使用非 root 时children,您还需要将数据中子属性名称的每个实例也更改为新名称。这意味着如果您想将根更改为results,您的树数据实际上必须看起来像这样:

echo "
{
    'success': true, 
    'variable': 100, 
    'results': 
    [
    { 'id' : '1' , 'text' : '1', 'expanded': true, 
        'results':[
            { 'id' : '5' , 'text' : '5', 'leaf':true},
            { 'id' : '6' , 'text' : '6', 'leaf':true}
        ]
    },
    { 'id' : '2' , 'text' : '2', 'leaf':true},
    { 'id' : '3' , 'text' : '3', 'leaf':true},
    { 'id' : '4' , 'text' : '4', 'leaf':true},
    { 'id' : '7' , 'text' : '7', 'leaf':true},
    { 'id' : '8' , 'text' : '8', 'leaf':true},
    { 'id' : '9' , 'text' : '9', 'leaf':true},
    { 'id' : '10' , 'text' : '10', 'expanded': true, 
        'results':[
            { 'id' : '11' , 'text' : '11', 'leaf':true},
            { 'id' : '12' , 'text' : '12', 'leaf':true}
        ]
    }
    ]
}";

另一种选择是将顶级results属性名称更改为children并将商店的根标记为children.

于 2013-09-23T13:45:29.107 回答
1

检查您的自动加载配置拼写。

 var store = Ext.create('Ext.data.TreeStore', {
        //    autoload: false,
            autoLoad : false,
            proxy: {
                type: 'ajax',
                url: 'data.php',
                reader: {
                    type: 'json',
                    root: 'results'                 
                }
            }
          });
于 2013-09-23T09:42:56.767 回答
0

你可以像下面一样添加根数据来存储吗

var store = Ext.create('Ext.data.TreeStore', {
            autoLoad : false,
            root: {
                text: 'Corporate Media',
                id: '0',
                expanded: true
            }
            proxy: {
                type: 'ajax',
                url: 'data.php',
                reader: {
                    type: 'json',
                    root: 'results'                 
                }
            }
          });
于 2013-09-23T13:01:07.427 回答