你有一个我需要在Jqgrid中显示的xml。任何人都可以帮助让这个工作。如果我遗漏了代码中的任何其他设置,请告诉我
我的xml数据:
<entry>
<properties xmlns="http://example.com" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<property>
<name>header1</name>
<value>value 1.1</value>
</property>
<property>
<name>Header2</name>
<url>http://localhost/locator.aspx</url>
<value>value 1.2 </value>
</property>
<property>
<name>header 3</name>
<value>value 1.3 </value>
</property>
</properties>
</entry>
<entry>
<properties xmlns="http://example.com" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<property>
<name>header1</name>
<value>value 2.1</value>
</property>
<property>
<name>Header2</name>
<url>http://localhost/locator.aspx</url>
<value>value 2.2 </value>
</property>
<property>
<name>header 3</name>
<value>value 2.3</value>
</property>
</properties>
</entry>
绑定JqGrid,如下所示但不能正常工作
function loadXMLDoc(data)
{
$("#loadXMLData").jqGrid({
url: 'local',
datatype: "xml",
height: 'auto',
colModel: [
{ name:xmlmap: function (obj) {
return $(obj).attr('name');
}}
, width: 80, sorttype: 'int',
xmlmap: function (obj) {
return $(obj).attr('value');
}
],
xmlReader: {
root: "properties",
row: "property",
repeatitems: false
},
loadonce: true,
rowNum: 1000
});
我需要输入以下格式
<table border=1>
<tr>
<th>
header 1
</th>
<th>
header 2
</th>
<th>
header 3
</th>
</tr>
<tr>
<td>value 1.1</td>
<td>value 1.2</td>
<td>value 1.3</td>
</tr>
<tr>
<td>value 2.1</td>
<td>value 2.2</td>
<td>value 2.3</td>
</tr>
<tr>
<td>value 3.1</td>
<td>value 3.2</td>
<td>value 3.3</td>
</tr>
</table>
&#13;
答案 0 :(得分:0)
答案 1 :(得分:0)
您可以参考此Convert XML to JSON (and back) using Javascript的SO帖子,或点击此链接到Convert XML to JSON
如果您已经提供了生成源XML文件,那么最好直接生成JSON格式的colModel和数据,而不是稍后将其转换为JSON。