I use the following code to rename jstree node (with crrm plugin):
$('#categoriesTree').jstree('rename');
How do I k开发者_运维知识库now whether the node was successfully renamed (by pressing Enter) or renaming was cancelled (by pressing Esc)? Event 'rename_node.jstree' doesn't provide useful information.
You can't know it by built-in functions but you can modify jquery.jstree.js.
In non-compressed version find string _show_input : function (obj, callback)
(near line 1263) and you'll see:
"blur" : $.proxy(function () {
var i = obj.children(".jstree-rename-input"),
v = i.val();
if(v === "") { v = t; }
h1.remove();
i.remove(); // rollback purposes
this.set_text(obj,t); // rollback purposes
this.rename_node(obj, v);
callback.call(this, obj, v, t);
obj.css("position","");
console.log('click outside or blur after esc / enter');
}, this),
"keyup" : function (event) {
var key = event.keyCode || event.which;
if(key == 27) { this.value = t; this.blur();
console.log('press esc');
return; }
else if (key == 13) {
this.blur();
console.log('press enter');
return;
} else {
h2.width(Math.min(h1.text("pW" + this.value).width(),w));
}
}, //...
I added three lines here (console.log
) and now you can see in console what's happening with your node. Instead of console.log
you can add some class to your element as flag and read it later or make your custom event, but I don't know how to do this. It's up to you.
精彩评论