【问题标题】:loading multiple xml tags in the same JQGrid [closed]在同一个 JQGrid 中加载多个 xml 标签 [关闭]
【发布时间】:2015-03-23 06:42:36
【问题描述】:

我的 xml 文件是这样的:

<abc>
   <a>
      <item>
         <name>...</name>
        <cost>....</cost>
      </item>
      .
      .
      .  
      .
   </a>
   <b>
      <item>
         <name>...</name>
         <cost>....</cost>
      </item>
      .
      .
      .  
      .
   </b>

我想在 jqgrid 上同时加载标签和 [不改变两个标签名称相同] 的值。当我使用 xmlReader 两次时,它只加载后来的根值.....任何人都知道如何加载两个标签????

【问题讨论】:

  • 你的 jqgrid 代码在哪里?

标签: jquery xml jqgrid


【解决方案1】:

读取此类 XML 数据的最简单方法是指定 xmlReader,如下所示

xmlReader : {
    root: "abc",
    row: "a>item,b>item",
    repeatitems: false
}

在更复杂的情况下,您可以使用 xmlReader 内部的函数:

xmlReader : {
    root: "abc",
    row: function (obj) {
        return $("a>item,b>item", obj);
    },
    repeatitems: false
}

xmlReader : {
    root: "abc",
    row: function (obj) {
        return $("a>item", obj).add("b>item", obj);
    },
    repeatitems: false
}

The corresponding demo阅读以下XML

<?xml version="1.0" encoding="UTF-8"?>
<abc>
   <a>
      <item>
         <name>Name A1</name>
         <cost>123</cost>
      </item>
      <item>
         <name>Name A2</name>
         <cost>234</cost>
      </item>
   </a>
   <b>
      <item>
         <name>Name B1</name>
         <cost>345</cost>
      </item>
      <item>
         <name>Name B2</name>
         <cost>456</cost>
      </item>
   </b>
</abc>

并将结果显示为

它使用代码

$("#list").jqGrid({
    url: "Ambkrish.xml",
    datatype: "xml",
    gridview: true,
    autoencode: true,
    pager: "#pager",
    rowNum: 10,
    rowList: [10, 20, 50],
    viewrecords: true,
    height: "auto",
    xmlReader : {
        root: "abc",
        row: "a>item,b>item",
        repeatitems: false
    },
    colModel:[
        { name: "name", label: "Name" },
        { name: "cost", label: "Cost", formatter: "integer", sorttype: "integer", align: "right" }
    ],
    cmTemplate: {width: 200},
    loadonce: true
});

【讨论】:

  • 非常感谢。这行得通。
  • @Ambkrish:不客气!如果问题解决了,你应该"accept"答案。
猜你喜欢
  • 2011-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多