在XPage中创建Dojox树网格时出错

时间:2015-08-13 07:54:54

标签: javascript dojo xpages

我一直在尝试在XPage上创建一个树形网格,而在重新格式化网格时“抱歉,发生错误”。

下面的JSON字符串是我尝试呈现的内容:

var data = {"identifier": "name",
 "label": "name",
items: [
    {"name": "Africa", "": "continent", "children": "[
            { "name":"Egypt", "field":"country" },
            { "name":"Kenya", "field":"country", "children":"[
                { "name":"Nairobi", "field":"city" },
                { "name":"Mombasa", "field":"city" } ]"
            ]},
            { "name":"Sudan", "field":"country", "children":"[
                { "name":'Khartoum', "field":"city" }]"
            },
        { "name":'Asia', "field":"continent", "children":"[
            { "name":"China", "field":"country" },
            { "name":"India", "field":"country"},
            { "name":"Russia", "field":"country" },
            { "name":"Mongolia", "field":"country" } ]"
        }

     }
]}

包含上述var的以下Dojo代码位于onCleintLoad事件 - Cleint端:

var jsonStore = new ItemFileWriteStore({data:data});

var layout = [
     {name: "Continent",     field: "continent"},
     {name: "Country",     field: "country"}  

];  

var treeModel = new dijit.tree.ForestStoreModel({
  store: folderStore,
  query: {type:'name'},
  rootId: 'LandRoot',
  rootLabel: 'Land',
  childrenAttrs: ['children']
});

var grid = new dojox.grid.TreeGrid({
  treeModel: treeModel,
  structure: layout,
  showRoot: true 
}, 'treeGrid');

grid.startup();

dojo.connect(window, "onresize", grid, "resize");

1 个答案:

答案 0 :(得分:0)

通过在每个新类别的开头向String添加新值"level":"0"来解决问题:

{"level": 0,"name": "Africa", "": "continent", "children": "[.....

并在网格的ForestStoreModel中:

var treeModel = new dijit.tree.ForestStoreModel({
  store: folderStore,
  query: {type:'name'},
  rootId: 'LandRoot',
  rootLabel: 'Land',
  childrenAttrs: ['children']
});

我将选择类别项所需的查询属性更改为query: {level:"0"},。这是诅咒错误的行,因为。type:'name'在JSONString中不存在。