问题
写【草书文档】这个应用的时候用到了目录树,相关配置挺多的,留存一下。
jstree中文官网
jsttee英文官网
英文官网要比中文的版本高一些,所以用要用github最新版的,看文档就都差不多了。
代码解析
$("#menu").jstree({
"core": {
"check_callback" : true,
"themes": {"stripes": true},
"data": d.menu
},
contextmenu : {
items : function(node){
let menu = {
createCatalog : {
label : "新建目录",
icon : "fa fa-folder-open",
action : function (node) {
var inst = $.jstree.reference(node.reference),
obj = inst.get_node(node.reference);
inst.create_node(obj, {type:"catalog"}, "last", function (new_node) {
console.log(new_node)
try {
new_node.text="新建目录";
inst.edit(new_node);
} catch (ex) {
setTimeout(function () { inst.edit(new_node); },0);
}
})
}
},
createPage : {
label: "新建文档",
icon: "fa fa-file-o",
action : function (node) {
var inst = $.jstree.reference(node.reference),
obj = inst.get_node(node.reference);
inst.create_node(obj, {type:"page"}, "last", function (new_node) {
console.log(new_node)
try {
new_node.text="新建文档";
inst.edit(new_node);
} catch (ex) {
setTimeout(function () { inst.edit(new_node); },0);
}
})
}
},
rename : {
label: "重命名",
icon: "fa fa-share",
action : function (node) {
var inst = $.jstree.reference(node.reference),
obj = inst.get_node(node.reference);
inst.edit(obj);
}
},
delete : {
label: "删除",
icon: "fa fa-times",
action : function (node) {
var inst = $.jstree.reference(node.reference),
obj = inst.get_node(node.reference);
if(inst.is_selected(obj)) {
inst.delete_node(inst.get_selected());
} else {
inst.delete_node(obj);
}
}
},
}
if(node.type == "page"){
// 文档-重命名、删除
delete menu.createCatalog;
delete menu.createPage;
}
return menu;
}
},
types : {
root : {
icon : "fa fa-home",
valid_children : ["catalog","page"]
},
catalog : {
icon : "fa fa-folder-open",
valid_children : ["catalog","page"]
},
page : {
icon : "fa fa-file-o",
valid_children : []
}
},
plugins : ["contextmenu", "dnd", "search","state", "types", "wholerow"]
}).on("changed.jstree",function(e,d){
// console.log(d)
// if(d.node.children.length == 0 && d.node.original.type == "page"){
// console.log(d.node.id)
// }
});
《致我的星星》韩国剧高清在线免费观看:https://www.jgz518.com/xingkong/119870.html