javascript - JQGrid 数据未使用 xml 加载

标签 javascript jquery xml jqgrid

我已经看到类似问题的答案,但没有帮助。网格正在显示,甚至数据正在传递,但唯一的问题是它没有加载到 jqGrid 中。 我检查了浏览器中的响应,数据正在以 XML 格式发送。所以,唯一的问题是它没有显示在浏览器中。

var lastsel2;
            $(function(){ 
                  $("#list1").jqGrid({
                    //url:'process/roles/GetRoles1.php',
                    url: 'processDragonDisplay.php',
                    datatype: 'xml',
                    mtype: 'GET',
                    autowidth: true,
                    height: 'auto',

                    colNames:['name', 'body', 'active_flag','Action'],
                    colModel :[
                      {name:'name', index:'name',   search:true, sortable: true}
                      ,{name:'body', index:'body',  search:true, sortable: true}
                      ,{name:'active_flag', index:'active_flag', width:30, sortable: true}
                      ,{name: 'choice', index: 'choice',width: 50, sortable: false }

                    ],
                    pager: '#pager1',
                    rowNum:10,
                    rowList:[10,20,30],
                    sortname: 'name',
                    sortorder: 'asc',
                    viewrecords: true,
                    gridview: true,
                    caption: 'Templates',
                    editurl: 'processDragonDisplay.php',
                    onSelectRow: function(id) {
                        $('#rowID').html(id);
                        //$('#userId123').attr('value', id);
                        $('#list2').trigger("reloadGrid");
                        if(id && id!==lastsel2){
                            jQuery('#list1').restoreRow(lastsel2);
                            jQuery('#list1').editRow(id,true);
                              lastsel2=id;
                        }
                    },
                    loadComplete: function(){ 
                        var ids = jQuery("#list1").getDataIDs();
                        for(var i=0;i<ids.length;i++){ 
                            var cl = ids[i];
                            ce = "<span class='ui-icon ui-icon-pencil' onclick=editData('"+cl+"');></span>"; 
                            $("#list1").jqGrid('setRowData', ids[i] , { choice: ce });
                        }
                    }
                  }).navGrid("#pager1",{edit:false, add:false, del:true});
                  //$("#list1").jqGrid('inlineNav','#pager1', {edit:false, del: false, add: false});
                });

带有 XML 数据的响应:

<?xml version='1.0' encoding='utf-8'?><rows><page>1</page><total>1</total><records>7</records><row id='A-000002'><cell>foo</cell><cell>bar yes ok</cell><cell>Y</cell><cell></cell></row><row id='A-000009'><cell>hello</cell><cell>hwq</cell><cell>Y</cell><cell></cell></row><row id='A-000013'><cell>nnnnn</cell><cell>nnnn</cell><cell>n</cell><cell></cell></row><row id='A-000007'><cell>t1</cell><cell>Your appointment for TOken  at  for  will be at </cell><cell>Y</cell><cell></cell></row><row id='A-000008'><cell>t1</cell><cell>Your appointment for TOken  at for  will be at </cell><cell>Y</cell><cell></cell></row><row id='A-000011'><cell>test2</cell><cell>test2</cell><cell>n</cell><cell></cell></row><row id='A-000015'><cell>wwwww</cell><cell>wwwww</cell><cell>g</cell><cell></cell></row></rows>

最佳答案

您的 XML 数据格式无效。查看 wiki 中的一些示例。您必须使用 xmlReader 将 XML 数据映射到网格。

例如:

xmlReader: { root:"result", row:"invoice"  }

将映射到以下数据格式:

<invoices> 
   <request>true</request> 
   ... 
   <result> 
      <invoice> 
         <cell>data1</cell> 
         <cell>data2</cell> 
         <cell>data3</cell> 
         <cell>data4</cell> 
         <cell>data5</cell> 
         <cell>data6</cell> 
      </invoice> 
      ... 
   </result> 
</invoices>

关于javascript - JQGrid 数据未使用 xml 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13271660/

相关文章:

javascript - 延迟 addClass jQuery

javascript - 我不明白为什么设置在具有 set 属性的构造函数的执行上下文中定义的值不会更改该值

javascript - Node.js 服务器无响应

javascript - 如何使用 JavaScript 追加插入带有样式属性的选项值?

php - 如何使用 jquery.validate 和 ?lang= 以不同语言显示 "please fill required field"?

C# XML --> 如何获取属于该attributes元素的属性值和xpath

xml - Notepad++ XML Display on separate lines like Internet Explorer Display Of XML

python - 我如何使用 python 针对 dtd 验证 xml?

javascript - 如何在插画脚本中将 CMYK 转换为 RGB?

javascript - 如何在客户端呈现 WebUserControl