【发布时间】:2011-07-25 11:17:35
【问题描述】:
我们有一个可以有不同类型节点的 JSTree,我必须为每个节点创建一个自定义菜单。
我已经到了这一点:
<script type="text/javascript">
// Initialization function for JTree. We can not mve this in a different file, because Genshi placeholders won't be replaced there.
$(function () {
$("#tree4").jstree({
contextmenu: {
"items" : createDefaultMenu
},
"plugins": ["themes", "json_data", "ui", "crrm", "contextmenu"],
"json_data": {"ajax": { url: "/project/readjsonstructure/${project.id}",
success: function (d) { return eval(d); }
}}
});
});
function createDefaultMenu(obj)
{
return {
create: false,
rename: false,
remove: false,
ccp: false,
launch_viewer: {
label: "Launch viewer",
action: function (obj) {
alert('Should launch here.')
},
seperator_after: false,
seperator_before: false
}
}
}
</script>
现在从我所读到的 obj 应该包含 JSTree 中当前单击的节点(如果我错了,请纠正我)。但是现在我如何找出这是什么类型的节点呢? readjson 结构返回一个:
encoder = JSONEncoder()
return encoder.iterencode(result)
其中 JSONEncoder 来自 simplejson,结果是具有以下结构的字典:
{ data: {
title: "root",
icon: "/static/style/nodes/nodeRoot.png"},
state:"open",
attr:{id:"projectID"},
children: [ data { .....
【问题讨论】:
标签: javascript jstree