我正在尝试将我的 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 部分中......