【问题标题】:jqGrid xml parsing with multiple namespace具有多个命名空间的 jqGrid xml 解析
【发布时间】:2014-06-14 06:20:20
【问题描述】:

我正在尝试使用 jqGrid 4.6 和 jquery 1.11 呈现我的 xml。我在使用命名空间读取属性时遇到问题。

下面是我的xml:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
 <feed>
   <id>1234/</id>
   <title type="text">ABCD</title>

   <entry>
     <id>1</id>
     <title type="text">Entry 1</title>
      <author>
       <name />
      </author>
     <content type="application/xml">
      <m:properties>
       <d:ContentTypeID>1</d:ContentTypeID>
       <d:TitleOfItem />
       <d:lastupdated>2014-04-22</d:lastupdated>
      </m:properties>
     </content>
  </entry>
  <entry>
      <id>2</id>
      <title type="text">Entry 2</title>
      <author>
        <name />
      </author>
      <content type="application/xml">
        <m:properties>
        <d:ContentTypeID>2</d:ContentTypeID>
        <d:TitleOfItem />
        <d:lastupdated>2014-04-22</d:lastupdated>
        </m:properties>
      </content>
   </entry>
</feed>

网格脚本:

<script type="text/javascript">

jQuery(document).ready(function(){

$("#grid")
        .jqGrid({
          url:'mytemplate.xml',
          datatype: "xml",
          xmlReader: {
                root:"feed",
                row:"entry",
                repeatitems:false
          },
          colModel:[
                      {name:'id', index:'id', width:100, align:'center', xmlmap: "id"},
                      {name:'ContentTypeID', index:'invid', width:100, align:'center', xmlmap:"????"}
                    ],
            height:250,
            rowNum:10,
            rowList:[10,20,30],
            viewrecords: true,
            loadonce: true
});

});


</script>

如何从上述 xml 中读取 ContentTypeID? 我试过这个功能

xmlmap: function (obj) {
            return $(obj).find(">content>RequestedDeliveryDetails").attr("ContentTypeID");
        }

还有

xmlmap: "[nodeName=content.m:properties.d:ContentTypeID]" },

到目前为止没有运气。

提前致谢!

【问题讨论】:

  • 您使用哪些网络浏览器以及哪个版本?

标签: javascript jquery xml jqgrid namespaces


【解决方案1】:

我找到了解决方案,需要在指定命名空间节点名称时转义“:”

xmlmap: "ns\\:nodeName" }

所以对于我上面的例子 xml

colModel:[
  {name:'id', index:'id', width:100, align:'center', xmlmap: "id"},
  {name:'ContentTypeID', index:'invid', width:100, align:'center', xmlmap:"d\\:ContentTypeID"}
 ]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 2011-01-30
    • 2021-11-23
    • 2011-01-30
    • 1970-01-01
    • 2012-08-15
    相关资源
    最近更新 更多