fre*_*yle 5 extjs extjs4.1 extjs4.2
我创建了一个TreePanel中,我创造store
像
var store = Ext.create('Ext.data.TreeStore', {
autoload: false,
proxy: {
type: 'ajax',
url: 'data.php',
reader: {
type: 'json',
root: 'results'
}
}
});
Run Code Online (Sandbox Code Playgroud)
我的服务器打印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}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行我的代码时,我看到了firebug,而且总是运行GET http://localhost/example/data.php...
从不停止:(
而且我的树增加了两倍
如何解决这个问题
编辑
在实际我用别名定义我的treepanel并使用它作为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()
});
Run Code Online (Sandbox Code Playgroud)
这是我的 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}
]
}
]
}";
Run Code Online (Sandbox Code Playgroud)
你在这里有什么我认为是树店里的bug.当您更改阅读器以使用不是的根时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}
]
}
]
}";
Run Code Online (Sandbox Code Playgroud)
另一个选项是将顶级results
属性名称更改为children
并将商店的根标记为children
.
归档时间: |
|
查看次数: |
3965 次 |
最近记录: |