如何在jqGrid中映射xml? [英] How to map an xml in jqGrid?

查看:55
本文介绍了如何在jqGrid中映射xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jqGrid,我有一个给定的xml我希望映射到jqGrid

I am using jqGrid, I have a given xml which i want to be mapped to jqGrid

<list>
<com.abc.db.ConfigInfo>
<cfgId>83</cfgId>
<cfgName>test</cfgName>
<cfgDesc>test</cfgDesc>
<cfgType>test</cfgType>
<fileName>csmclientbenz.xml</fileName>
<absolutePath>../webapps/csm/files//1-105101/csmclientbenz.xml</absolutePath>
<emailAddress>abhishek@abc.com</emailAddress>
<projectId>1-105101</projectId>
<hostname>benz</hostname>
<createDate>2011-06-15 15:29:55.0 IST</createDate>
<updateDate>2011-06-15 15:29:55.0 IST</updateDate>
<state>1</state>
<productId>1</productId>
</com.abc.db.ConfigInfo>
<com.abc.db.ConfigInfo>
<cfgId>102</cfgId>
<cfgName>cfgname1</cfgName>
<cfgDesc>test</cfgDesc>
<cfgType>test</cfgType>
<fileName>csmclientestilo.xml</fileName>
<absolutePath>../webapps/csm/files//1-105101/csmclientestilo.xml</absolutePath>
<emailAddress>abhishek@abc.com</emailAddress>
<projectId>1-105101</projectId>
<hostname>estilo</hostname>
<createDate>2011-06-20 18:26:03.0 IST</createDate>
<updateDate>2011-06-20 18:26:03.0 IST</updateDate>
<state>1</state>
<productId>1</productId>
</com.abc.db.ConfigInfo>
</list>

我使用过这样的东西,但请帮助我从这里搬家,如何分配 xml 来自 XMLHttpRequest 到jqGrid

I used something like this, but please help me move from here, how shall i assign xml which comes from XMLHttpRequest to jqGrid

var xml=client.responseText;
         $('#configDiv').empty();
            $('<div width="100%">')
            .attr('id','configDetailsGrid')
            .html('<table id="list1" width="100%"></table>'+
                    '<div id="gridpager"></div>'+
                '</div>')       
            .appendTo('#configDiv');    

            jQuery("#list1").jqGrid({
                datatype: "clientSide",
                height: 250,
                colNames:['cfgId','cfgName', 'cfgDesc', 'cfgType','absolutePath', 'updateDate', 'fileName'],
                colModel:[
                    {name:'cfgId',index:'cfgId', width:90, align:"right"},
                    {name:'cfgName',index:'cfgName', width:90, align:"right"},
                    {name:'cfgDesc',index:'cfgDesc', width:90, align:"right"},
                    {name:'cfgType',index:'cfgType', width:90, align:"right"},
                    {name:'absolutePath',index:'absolutePath', width:90, align:"right"},
                    {name:'updateDate',index:'updateDate', width:90, align:"right"},
                    {name:'fileName',index:'fileName', width:90, align:"right"},
                ],
                pagination:true,
                pager : '#gridpager',
                rowNum:10,
                scrollOffset:0,
                height: 'auto',
                autowidth:true,
                viewrecords: true,
                gridview: true,
 xmlReader: { 
                    root : "list",
                    row: "com.abc.db.ConfigInfo",
                    repeatitems: false,
                    id: "ASIN"
                    },
                edit:false,
                add:false,
                del:false

            });

稍后我还需要隐藏 cfgid 文件名。谢谢请帮助

Later I also need to hide cfgid and filename. Thanks please help

推荐答案

你有XML节点名称中的特殊字符'。'(点),所以你必须逃脱像这样的角色:

You have special character '.' (point) in the name of XML node, so you have to escape the character like so:

row: "com\\.abc\\.db\\.ConfigInfo"

此外,您的数据包含节点而非属性,因此您不需要先转换数据它可以被jqGrid读取。所以下面的代码将直接使用XML数据:

Moreover you data has nodes and not attributes, so you don't need convert the data before it can be read by jqGrid. So the following code will use the XML data directly:

jQuery('#list').jqGrid({
  url: 'Ricky.xml',
  datatype: 'xml',
  colNames:['cfgId','cfgName', 'cfgDesc', 'cfgType','absolutePath', 'updateDate', 'fileName'],
  colModel:[
      {name:'cfgId',index:'cfgId', width:90, align:"right"},
      {name:'cfgName',index:'cfgName', width:90, align:"right"},
      {name:'cfgDesc',index:'cfgDesc', width:90, align:"right"},
      {name:'cfgType',index:'cfgType', width:90, align:"right"},
      {name:'absolutePath',index:'absolutePath', width:90, align:"right"},
      {name:'updateDate',index:'updateDate', width:90, align:"right"},
      {name:'fileName',index:'fileName', width:90, align:"right"},
  ],
  pager : '#pager',
  rowNum:10,
  scrollOffset:0,
  height: 'auto',
  autowidth:true,
  viewrecords: true,
  gridview: true,
  xmlReader: {
      root : "list",
      row: "com\\.abc\\.db\\.ConfigInfo",
      repeatitems: false
  }
});

查看工作演示

这篇关于如何在jqGrid中映射xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆