我想使用这个http://www.jstree.com/documentation/contextmenu
我可以创建、删除、编辑节点,但我的问题是,我如何获得创建节点的值或 id 如何获得已删除节点的值或 id,因为我将插入数据库。和这里的javascript代码
http://static.jstree.com/v.1.0pre/jquery.jstree.js
对于创建进程,我发现这段代码可能属于下面的创建进程。
// Basic operations: create
create_node: function (obj, position, js, callback, is_loaded) {
obj = this._get_node(obj);
position = typeof position === "undefined" ? "last" : position;
var d = $("<li />"),
s = this._get_settings().core,
tmp;
if (obj !== -1 && !obj.length) { return false; }
if (!is_loaded && !this._is_loaded(obj)) { this.load_node(obj, function () { this.create_node(obj, position, js, callback, true); }); return false; }
this.__rollback();
if (typeof js === "string") { js = { "data": js }; }
if (!js) { js = {}; }
if (js.attr) { d.attr(js.attr); }
if (js.metadata) { d.data(js.metadata); }
if (js.state) { d.addClass("jstree-" + js.state); }
if (!js.data) { js.data = this._get_string("new_node"); }
if (!$.isArray(js.data)) { tmp = js.data; js.data = []; js.data.push(tmp); }
$.each(js.data, function (i, m) {
tmp = $("<a />");
if ($.isFunction(m)) { m = m.call(this, js); }
if (typeof m == "string") { tmp.attr('href', '#')[s.html_titles ? "html" : "text"](m); }
else {
if (!m.attr) { m.attr = {}; }
if (!m.attr.href) { m.attr.href = '#'; }
tmp.attr(m.attr)[s.html_titles ? "html" : "text"](m.title);
if (m.language) { tmp.addClass(m.language); }
}
tmp.prepend("<ins class='jstree-icon'> </ins>");
if (!m.icon && js.icon) { m.icon = js.icon; }
if (m.icon) {
if (m.icon.indexOf("/") === -1) { tmp.children("ins").addClass(m.icon); }
else { tmp.children("ins").css("background", "url('" + m.icon + "') center center no-repeat"); }
}
d.append(tmp);
});
d.prepend("<ins class='jstree-icon'> </ins>");
if (obj === -1) {
obj = this.get_container();
if (position === "before") { position = "first"; }
if (position === "after") { position = "last"; }
}
switch (position) {
case "before": obj.before(d); tmp = this._get_parent(obj); break;
case "after": obj.after(d); tmp = this._get_parent(obj); break;
case "inside":
case "first":
if (!obj.children("ul").length) { obj.append("<ul />"); }
obj.children("ul").prepend(d);
tmp = obj;
break;
case "last":
if (!obj.children("ul").length) { obj.append("<ul />"); }
obj.children("ul").append(d);
tmp = obj;
break;
default:
if (!obj.children("ul").length) { obj.append("<ul />"); }
if (!position) { position = 0; }
tmp = obj.children("ul").children("li").eq(position);
if (tmp.length) { tmp.before(d); }
else { obj.children("ul").append(d); }
tmp = obj;
break;
}
if (tmp === -1 || tmp.get(0) === this.get_container().get(0)) { tmp = -1; }
this.clean_node(tmp);
this.__callback({ "obj": d, "parent": tmp });
if (callback) { callback.call(this, d); }
return d;