2

我遇到了自动加载树网格的问题。目前我的结构只有两层深。

1
    a
    b
    c 
2
    a

当我单击展开节点时,网格似乎再次添加了根节点的另一个实例,以及应该根据所选根节点显示的任何子节点。

1
1
    a
    b
    c

下面是选择根节点之前的 XML:

<?xml version="1.0" encoding="UTF-8"?>
<rows>
    <page>1</page>
    <total>1</total>
    <records>1</records>
    <row>
        <cell>1112</cell>
        <cell>Parent 1</cell>
        <cell>0</cell>
        <cell>NULL</cell>
        <cell>false</cell>
        <cell>false</cell>
    </row>
</rows>

下面是选择根节点后的 XML:

<?xml version="1.0" encoding="UTF-8"?>
<rows>
    <page>1</page>
    <total>1</total>
    <records>1</records>
    <row>
        <cell>1112</cell>
        <cell>Parent 1</cell>
        <cell>0</cell>
        <cell>NULL</cell>
        <cell>false</cell>
        <cell>false</cell>
    </row>
    <row>
        <cell>5207</cell>
        <cell>Child 1</cell>
        <cell>1</cell>
        <cell>1112</cell>
        <cell>false</cell>
        <cell>false</cell>
    </row>
</rows>

另外,这是我的配置:

$(document).ready(function(){
    $("#gReport").jqGrid({
        treeGrid: true,
        treeGridModel: 'adjacency',
        ExpandColumn: 'company',
        url: document.forms['frmReport'].elements['gaddr'].value,
        datatype: 'xml',
        mtype: 'GET',
        colNames: ["ID", "Company"],
        colModel: [
            {name: 'id', index: 'id', width: 1, hidden: true, key: true},
            {name: 'company', index: 'company', width: 40, hidden: false, sortable: true}
        ],
        rowNum: -1,
        width: 980,
        height: 'auto',
        pager: false,
        caption: ''
    }),
});

任何帮助将不胜感激。谢谢。-克里斯

4

1 回答 1

2

你描述的行为真的很有趣!问题是子节点“Child 1”没有标记为叶子<cell>false</cell>后面的行<cell>1112</cell>是isLeaf值)。因此,在用户单击“子 1”后,必须显示其所有子项。因为在您的输入中未定义“已加载”列的值,所以树形网格尝试从服务器加载 id=5207 的“子 1”节点的子节点。所以对相同url的请求带有附加参数

nodeid=5207&parentid=1112&n_level=1

将会完成。因为您的服务器只是忽略参数并返回相同的 XML 数据,所以请看疯狂的图片

在此处输入图像描述

(请参阅此处的演示)。要解决此问题,您应该将“Child 1”节点标记为叶子:

<row>
    <cell>5207</cell>
    <cell>Child 1</cell>
    <cell>1</cell>
    <cell>1112</cell>
    <cell>true</cell> <!-- here the "false" was changed to "true" -->
    <cell>false</cell>
</row>

并收到以下树网格

在此处输入图像描述

(请参见此处的演示)或在 XML 文件中为“已加载”列添加具有“真”值的附加数据:

<row>
    <cell>1112</cell>
    <cell>Parent 1</cell>
    <cell>0</cell>
    <cell>NULL</cell>
    <cell>false</cell> <!-- is leaf -->
    <cell>true</cell>  <!-- should be expanded -->
    <cell>true</cell>  <!-- is loaded -->
</row>
<row>
    <cell>5207</cell>
    <cell>Child 1</cell>
    <cell>1</cell>
    <cell>1112</cell>
    <cell>false</cell> <!-- is leaf -->
    <cell>false</cell> <!-- should be expanded -->
    <cell>true</cell>  <!-- is loaded -->
</row>

并接收网格

在此处输入图像描述

(请参阅此处的演示)。我建议您以任何方式为“已加载”列包含“真实”值。您获得的额外好处是您将能够在加载时扩展任何节点。例如,在上一个演示中,我在根节点的“expanded”列中设置了“true”值,因此它将在加载时展开。

于 2011-05-03T09:22:58.997 回答