使用下面的JSON字符串,我用它在我的Xpages应用程序上呈现dojo treegrid:
var data= {identifier: 'name',
label: 'continent',
items: [
{"name": "Africa", "field": "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" } ]"
}
}
]}
我尝试创建一个onClick事件,每次我在节点上看到一个警报节点未定义的执行我如何获得项目的actaull值?
var store= new dojo.data.ItemFileReadStore({data: data});
var model = new dijit.tree.ForestStoreModel({
store: store,
query: {field:"continent"},
labelAttr :"name"
rootId: 'id',
rootLabel: 'continent',
childrenAttrs: ['children']
});
var grid = new dojox.grid.TreeGrid({
treeModel: model,
showRoot: true,
openOnDblClick:true,
onClick : function(item, node, evt){
var id=store.getValue(item,"name");
alert("Execute of node " + id)
}
}, 'treeGrid');
grid.startup();
答案 0 :(得分:0)
我建议在触发onclick事件时检查store
是什么。请记住,onclick事件将作为客户端JavaScript附加到每个项目。我怀疑它不会在你编写它的上下文中运行,但它是一个离散函数。因此它只能访问传递给函数的变量 - item
,node
和evt
- 并且无法访问在函数范围之外声明的变量,例如存储。
您可以从item
或node
变量导航到数据存储。