如何使用jstree添加文件图标?

时间:2012-10-22 15:55:45

标签: javascript jquery jstree

我有下面的代码,需要在单击add_file($(“#treeFile”)时向jstree文件结构添加一个file.png图标.jstree(“create”));

  $("#treeFile").jstree({
                "plugins" : ["themes","html_data","ui","crrm","types"],
                "types" : {
                        "max_depth" : -2,
                        "max_children" : -2,
                        "valid_children" : [ "drive" ],
                        "types" : {
                                "default" : {
                                        "valid_children" : "none",
                                        "icon" : { "image" : "/tree/_demo/file.png"}
                                                         }
                              }
                      }   
                })
                    .bind("select_node.jstree", function (event, data) {

    });

$("#treeMenu li").click(function()
{
    if($(this).text() == "add_file")
    {
        $("#treeFile").jstree("create");

    }else if($(this).text() == "add_folder")
    {
        $("#treeFile").jstree("create");

    }else if($(this).text() == "rename")
    {
        $("#treeFile").jstree("rename");

            }else if($(this).text() == "remove")
    {
        $("#rootNode").jstree("remove");
    }else
    {}

2 个答案:

答案 0 :(得分:3)

'icon': 'jstree-file'属性添加到节点

答案 1 :(得分:1)

jstree方法的语法添加type属性以显示文件图标:

$(“#treeFile”)。jstree(“create”,null,“inside”,{attr:{“rel”:“file”}});

问题代码将“默认”更改为“文件”