如何阻止 extjs 树面板无限加载?
最后,在与 extjs 树面板、树存储和构建自定义读取器来读取和转换 pentaho 数据斗争了两周后,我成功地将 pentaho 数据加载到 extjs 的树面板中。
现在我的树面板正在无限加载相同的数据。 Treepanel 如下所示:
我的 json 数据的一部分如下所示:
{
{name: 'US', candidateCount: 3, children: []},
{name: 'India', candidateCount: 922, children: [
{name: 'Goa', candidateCount:124, children: []},
{name: 'Maharashtra', candidateCount: 43, children: [
{name: 'Pune', candidateCount: 3},
{name: 'Mumbai', candidateCount: 33},
{name: 'Kolhapur', candidateCount: 4},
{name: 'XXX', candidateCount: 3},
]}
]},
{name: 'UK', candidateCount: 1, children: []},
}
如上图所示,之后扩展India
节点,它再次加载国家级别的数据(即国家名称美国、英国、印度、英国)。实际上我想显示州级数据,例如马哈拉施特拉邦、果阿邦的数据。而不是该树面板再次加载相同的数据。
如何避免这种行为?我已经将美国、英国和印度节点的 leaf
属性设置为 false
。
我尝试将 Expanded
属性设置为 true
但随后 Treepanel 不断加载相同的节点,并且我的浏览器选项卡被挂起。
请告诉我如何避免这种情况?我希望树面板仅加载数据一次。
编辑-此问题的解决方案
我通过在存储的 append
事件上添加侦听器,然后将节点的 leaf
值设置为 true
来解决此问题我想成为叶子。
Finally after struggling with extjs tree panel, tree store and building custom reader to read and convert pentaho data for 2 weeks I have managed to load pentaho data into treepanel of extjs.
Now my Tree panel is loading same data infinitely.
Treepanel looks as follows :
Part of my json data looks as follows :
{
{name: 'US', candidateCount: 3, children: []},
{name: 'India', candidateCount: 922, children: [
{name: 'Goa', candidateCount:124, children: []},
{name: 'Maharashtra', candidateCount: 43, children: [
{name: 'Pune', candidateCount: 3},
{name: 'Mumbai', candidateCount: 33},
{name: 'Kolhapur', candidateCount: 4},
{name: 'XXX', candidateCount: 3},
]}
]},
{name: 'UK', candidateCount: 1, children: []},
}
As you can see in image above, after expanding India
node it has again loaded data of country level (i.e. country names US, uk, India, UK). Actually I want to show state level data like data of Maharashtra, Goa. Instead of that treepanel is again loading same data again.
How to avoid this kind of behavior? I have already set leaf
property of US, uk and India nodes to false
.
I tried setting Expanded
property to true
but then treepanel keeps loading same nodes again and again and my browser tab just gets hanged.
Please let me know how to avoid this? I want tree panel to load data only once.
EDIT - Solution to this problem
I solved this problem by adding listener on append
event of store and then setting leaf
value to true
for the nodes which I wanted to be leaf.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
正如 Edd 所说,如果您在代理自定义 rootProperty:'instanceList' 中设置,则必须将 json 中的所有“子级”更改为该属性,即“instanceList”。这是我的解决方案。
As Edd said, if you set in proxy custom rootProperty:'instanceList', you have to change all "children" in json to that property, ie 'instanceList'. It was my solution.
我的树面板和 JSON 数据也有同样的问题。我的treeStore看起来像这样:
并且我将“children”更改为“instanceList”的JSON
,并且我的树面板停止了无限循环,所以我想如果您将“name”更改为“children”?
I had the same problem with my treepanel and JSON data. My treeStore looks something like this:
And the JSON
I changed "children" for "instanceList" and my treepanel stopped doing that infinitely loop, so I guess If you change "name" for "children" ?
将数据项设置为:
将停止它。
Setting data item to:
will stop it.
加载树可能会被欺骗。尝试在这些节点上设置
loaded: true
。在开始点击之前,树是否正确加载?Loading trees can be tricking. Try setting
loaded: true
on those nodes. Before you start clicking around, is the tree properly loaded?确保所有没有任何孩子的父母都将“leaf”设置为“true” 或
有一个空的“子”节点。
并且所有子节点都将“leaf”设置为“true”(正如Asken已经提到的)
Make sure all parents that do not have any children have "leaf" set to "true" OR
have an empty "children" node.
AND all children nodes have "leaf" set to "true" (as already mentioned by Asken)
在我看来,任何孩子都会成为其家属的根。因此根属性和子属性必须具有相同的名称。我很高兴我找到了这个踏板。它救了我的命,因为无休止地重新装载树,我正准备开枪自杀
it seems to me that any child becomes a root to its dependents . So the root property and the children property MUST have the same NAME. I am very happy I found this tread. It saved my life I was about to shoot myself because of endless reloading the tree