0

我正在尝试将我的 listdata 转换为 JS 对象文字。

输出应如下所示:

dp.resources = [
                 { name: "Room A", id: "A", expanded: true, children:[
                         { name : "Room A.1", id : "A.1" },
                         { name : "Room A.2", id : "A.2" }
                         ] 
                 },
                 { name: "Room B", id: "B" },
                 { name: "Room C", id: "C" },
                 { name: "Room D", id: "D" },
                 { name: "Room E", id: "E" },
                 { name: "Room F", id: "F" },
                 { name: "Room G", id: "G" },
                 { name: "Room H", id: "H" },
                 { name: "Room I", id: "I" },
                 { name: "Room J", id: "J" },
                 { name: "Room K", id: "K" },
                ];

我正在使用这个 jquery 代码来加载主要房间:

dp.resources = [];
serviceUrl = "../_vti_bin/listdata.svc/Rooms()?$orderby=Order asc";
$.getJSON(serviceUrl, function(results) {
  $.each(results.d.results, function(i, item) {
   dp.resources.push({name:item.Title, id:item.Id, expanded: true, dynamicChildren: true});
  }); // end each
 dp.update();

现在,我将如何从另一个列表中检索孩子(例如 B.1)并将它们推送到我的 dp.resources 中的正确位置?我更喜欢将它嵌套到脚本的上述 $.each 部分中......

4

1 回答 1

0

并不是说它似乎对其他人感兴趣,但这是我使用 jquery ajax 从共享点列表中加载 daypilot 数据的最终代码:

// load resources
dp.resources = [];
branchUrl = "../_vti_bin/listdata.svc/Branches()?$orderby=Order asc";
$.getJSON(branchUrl, function(results) {
  $.each(results.d.results, function(i, item) {
   dp.resources.push({name:item.Title, id:"b_" + item.Id, expanded: true, dynamicChildren: true, children:[]});

   // load children
   dp.onLoadNode = function(args) {
    args.async = true;
    resourceURL = "../_vti_bin/listdata.svc/Resources()?$filter=Titel+eq+'" + args.resource.name + "'";
     $.getJSON(resourceURL, function(results) {
      $.each(results.d.results, function(i, item) {
       args.resource.children.push({name:item.Name, id:"r_" + item.Id});
      }); // end each
     }).then(function(){
         args.loaded();  
        });
   }; //end onLoadNode


  }); // end each
}).then(function() {
 dp.update();
}); // end thens 
于 2013-11-04T15:47:33.833 回答