【发布时间】:2015-07-13 10:58:44
【问题描述】:
我正在从 Web 服务(按需)绑定我的 jStree,它工作正常,现在我想使用上下文菜单插件重命名节点,上下文菜单按预期显示,只有一个项目是重命名,但是单击它时,节点不可编辑
我的jsTree初始化代码如下。
我已将“check_callback”属性设置为 true,并且还添加了一条允许重命名 TreeNode 的规则,
我已在控制台(Chrome 开发人员选项)中检查并验证“操作”方法正在被命中,并且我也正在获取当前节点数据,但在 .edit 方法调用之后没有任何反应,
我相信 .edit 方法是让节点可编辑,编辑完成后我应该得到 rename_node 事件。但这不会发生
如果我对相同的理解有错误,请纠正我
jQuery("#divTree").on("select_node.jstree", function (e, data) {
jQuery.AreaManagementInfo.CurrentlySelectedArea = data.node;
}).on('rename_node.jstree ', function (obj, val) {
alert('rename ');
}).jstree({
'plugins': ['contextmenu'],
'rules': {
"renameable": "all",
"multiple" : false
},
"contextmenu": {
"items": function ($node) {
return {
"Rename": {
"label": "Rename",
"action": function (data) {
var inst = $.jstree.reference(data.reference),
obj = inst.get_node(data.reference);
inst.edit(obj);
}
}
};
}
},
'core': {
'data': {
'type': 'POST',
'cache': true,
'contentType': 'application/json',
'url': Url,
'check_callback': true,
'themes': { "stripes": true },
'data': function (node) {
var parentId = 0;
if (node.id != "#") {
parentId = node.data.AreaId;
}
return JSON.stringify({ basicParam: basicParam, parentId: parentId });
},
'success': function (data) {
if (data.d != null) {
if (data.d != "") {
var length = data.d.length - 1;
}
}
return data.d;
},
'error': function (request, error) {
jQuery("#divTree").addClass("hide");
}
}
}
});
【问题讨论】:
-
我相信我在 jsTree 中设置规则的方式有问题,正如我提到的
"multiple":false但它仍然允许我选择多个节点(ctrl+click 允许选择多个节点) -
我也无法设置 jsTree 的主题是因为没有正确添加主题..??
标签: jquery contextmenu rename jstree