我在调用自定义菜单项的函数中。为什么node.attr('id')或$(node).attr('id')不起作用?
树初始化:
$("div#treeView").jstree({
plugins: ["themes", "ui", "json_data", "crrm", "contextmenu"],
themes: { "icons": false },
"json_data": jsondata,
contextmenu: { items: customMenu, select_node: true }
});
node.attr('type')返回undefined:
function customMenu(node) {
// The default set of all items
var items = {
deleteItem: { // The "delete" menu item
label: "Delete",
action: function () { alert("delete"); }
}
};
if (node.attr('type') == "report") delete items.deleteItem;
return items;
}
这是我向树添加节点时的结构:
CreateTreeNode: function (id, title, type, metadata) {
var newNode = {
"data":
{
"title": title,
"attr":
{
"id": id,
"type": type
}
},
"metadata": (metadata == undefined ? {} : metadata),
"children": []
};
return newNode;
}