【问题标题】:how to map multilayered jsondata to jqgrid如何将多层jsondata映射到jqgrid
【发布时间】:2013-08-30 14:02:14
【问题描述】:

大家好,我的数据如下所示:

时间表数据

[
  {ID:2, Name:QXC, Items:[{Status:1, Hours: 8},{Status:1, Hours: 4}]}, 
  {ID:5, Name:ABC, Items:[{Status:1, Hours: 6},{Status:1, Hours: 0}]}
]

我的网格看起来像:

  jQuery("#rowed5").jqGrid({        
    data: timeSheetData,
    datatype: "local",
    height: 250,
    colNames:['ID','Name','Monday','Tuesday'],
    colModel:[
              {name:'ContractID', index:'ContractID', jsonmap:'?????', width:200, editable:false, sortable:false},
              {name:'EmployeeName', index:'EmployeeName', jsonmap:'?????'' ,width:200, editable:false, sortable:false},
              {name:'Monday', index:'Monday', jsonmap:'?????', width:200, editable:false, sortable:false},
              {name:'Tuesday', index:'Tuesday'jsonmap:'?????'jsonmap:'timeSheetRow1.timeSheetItem2.WorkedHours', width:200, editable:false, sortable:false}
             ],
    caption: "Input Types",
    jsonReader: {repeatItems: false, root: "timeSheetRow1"}
  });

我很感兴趣我需要用什么来代替 ?????在我的 jqgrid 表中获取以下两行:

   2, QXC, 8, 4
   5, ABC, 6, 0

提前谢谢!

【问题讨论】:

    标签: javascript json jqgrid jqgrid-asp.net


    【解决方案1】:

    所以,我想通了。我的问题是我只查看对象值,而不是它的结构。因此,考虑到这一点,对象结构如下:

    //TimeSheetData:
    var timeSheetData = new Object();
    timeSheetData.Rows = [row1,row2]; /*Rows is an
    Array containing Row objects*/
    
    //Row:
    var row1 = new Object();
    row1.ID = 19;
    row1.Name = "F.L.";
    row1.Items = [item1, item2]; /*Items
    is an object with containing other objects(Item) and some properties*/
    
    //Item:
    var item1 = new Object();
    item1.Status = 0;
    item1.Hours = 6;
    

    所以,总而言之,我的问题(colModel 在我的情况下看起来如何)的答案是:

    ...,
    colModel:[
               {name:'ContractID', index:'ContractID', jsonmap:'ID', width:200, editable:false, sortable:false},
               {name:'EmployeeName', index:'EmployeeName', jsonmap:'Name' ,width:200, editable:false, sortable:false},
               {name:'Monday', index:'Monday', jsonmap:'Items.0.Hours', width:200, editable:false, sortable:false},
               {name:'Tuesday', index:'Tuesday', jsonmap:'Items.1.Hours', width:200, editable:false, sortable:false}
             ],
    jsonReader: {repeatItems: false, root: "Rows"}
    });
    jQuery("#rowed5")[0].addJSONData(timeSheetData.Rows);
    

    【讨论】:

      猜你喜欢
      • 2021-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 1970-01-01
      • 2015-12-19
      • 2013-12-13
      • 1970-01-01
      相关资源
      最近更新 更多