【问题标题】:jqGrid treegrid ignores expanded state when provided xml datajqGrid treegrid 在提供 xml 数据时忽略展开状态
【发布时间】:2012-10-23 03:17:33
【问题描述】:

我有这个问题,jqGrid中的treegrid在通过xml传递数据时忽略了最后一个选项(扩展节点或不扩展节点)。有人遇到过这个吗?有解决办法吗?也许是我的数据?这是产生问题的示例数据:

<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>

【问题讨论】:

    标签: javascript jqgrid treegrid


    【解决方案1】:

    在我看来,它更像是 TreeGrid 中的一个错误。不过,您可以通过loaded: true 属性添加到需要扩展的节点轻松解决问题。代码的the line 和上面的一些行(参见here)中的原因,其中loaded 属性(和ldat[loaded])将为undefined,因此所有项目的ldat[expanded] 将更改为undefined没有定义loaded

    The demo 演示解决方案。它使用您发布的 XML,但在 "Parent" 项目的定义末尾添加了额外的 &lt;cell&gt;true&lt;/cell&gt;

    ...
    <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>
    ...
    

    已更新:我认为修复错误(最初描述为here)最简单的方法是更改​​代码setTreeNodethe line

    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);
    

    the corresponding demo使用了固定代码。

    【讨论】:

    • 谢谢!我发现这个带有负载参数的旧错误,但创建者说它已经解决了......几个月前。我没有弄清楚如何在新版本中应用解决方法只是为了尝试,因为源代码已经改变,但它确实有效。谢谢!
    • @MihalisBagos:不客气!我将尝试进一步分析setTreeNode 的代码,并将我的建议发布到trirand。如果我这样做,我会通知你。
    • @MihalisBagos:我更新了我的答案,提出了修正错误的建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多