提供的xml数据时,jqGrid treegrid忽略扩展状态 [英] jqGrid treegrid ignores expanded state when provided xml data
问题描述
我有这个问题,当通过xml传递数据时,jqGrid中的treegrid会忽略最后一个选项(是否扩展节点).有人遇到过这个吗?有解决方案吗?也许是我的数据?这是产生问题的示例数据:
I have this problem, treegrid in jqGrid ignores the last option (expanded node or not) when passing data through xml. Anyone encountered this? Is there a solution? Maybe its my data? Here is a sample data that produces the problem:
<rows>
<page>1</page>
<total>0</total>
<records>4</records>
<row id='2'>
<cell>2</cell>
<cell>Parent</cell>
<cell>0</cell>
<cell>NULL</cell>
<cell>false</cell>
<cell>true</cell>
</row>
<row id='1'>
<cell>1</cell>
<cell>Child 1</cell>
<cell>1</cell>
<cell>2</cell>
<cell>true</cell>
<cell>false</cell>
</row>
<row id='3'>
<cell>3</cell>
<cell>Child 2</cell>
<cell>1</cell>
<cell>2</cell>
<cell>true</cell>
<cell>false</cell>
</row>
<row id='4'>
<cell>4</cell>
<cell>Child 3</cell>
<cell>1</cell>
<cell>2</cell>
<cell>true</cell>
<cell>false</cell>
</row>
</rows>
推荐答案
对我来说,它似乎更多是TreeGrid中的错误.不过,您可以通过将loaded: true
属性添加到需要扩展的节点上来轻松解决问题.代码该行中的原因和上面的几行(请参见此处),其中loaded
属性(和ldat[loaded]
)将为undefined
,因此对于所有未定义loaded
的项目,ldat[expanded]
都将更改为undefined
.
It seems for me more as a bug in TreeGrid. Nevertheless you can easy fix the problem by adding loaded: true
property to the node which need be expanded. The reason in the line of code and some above lines (see here) where loaded
property (and ldat[loaded]
) will be undefined
and so the ldat[expanded]
will be changed to undefined
for all items having no loaded
defined.
演示演示了解决方案.它使用您发布的XML,但在"Parent"
项目的定义末尾添加了附加的<cell>true</cell>
:
The demo demonstrate the solution. It uses XML which you posted but with additional <cell>true</cell>
added at the end of definition of "Parent"
item:
...
<row id='2'>
<cell>2</cell>
<cell>Parent</cell>
<cell>0</cell>
<cell>NULL</cell>
<cell>false</cell>
<cell>true</cell>
<cell>true</cell> <!-- added the element for loaded: true -->
</row>
...
已更新:我认为这是解决该错误的最简单方法(最初描述为代码setTreeNode
UPDATED: I think that the most easy way to fix the bug (originally described here) will be to change the line of code setTreeNode
ldat[expanded] = ((ldat[expanded] == "true" || ldat[expanded] === true) ? true : false) &&
ldat[loaded];
到以下
ldat[expanded] = ((ldat[expanded] == "true" || ldat[expanded] === true) ? true : false) &&
(ldat[loaded] || ldat[loaded] === undefined);
请参见相应的演示使用了固定代码.
See the corresponding demo used the fixed code.
这篇关于提供的xml数据时,jqGrid treegrid忽略扩展状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!