8

我需要有一个可从数据库配置的 jstree,但我遇到了图标问题(这只是我查询中包含图标名称的另一列)。问题是我无法正确显示它。

在此处输入图像描述

background-image:url('path');我通过添加属性以将图像指向标签中来构建此列表,<a>但我一直显示该文件夹图标(图像没有重复,但我将其包含在内以便更容易地可视化问题)。

如何让 jstree 不显示该文件夹?似乎 jstree 只是为整个树(或至少每个级别)构建一个图像。我不知道如何修改它。

这是上图的 html。

<ul style=""><li id="1227_1226" class="leaf jstree-leaf">
<ins class="jstree-icon">&nbsp;</ins>
            <a href="/arco/formatos/Estrategia desarrollo.doc" style="background-image:url('/arco/Menu/images/web.png;');" class="nothing"><ins class="jstree-icon">&nbsp;</ins>
                Instructivo desarrollo
            </a>
        </li>

        <li id="1227_1228" class="leaf jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>
            <a href="/arco/formatos/FO-0001 FormatoMantenimientoPlanificado-V1.doc" style="background-image:url('/arco/Menu/images/web.png;');" class="nothing"><ins class="jstree-icon">&nbsp;</ins>
                Mantenimiento planificado
            </a>
        </li>

        <li id="1227_1229" class="leaf"><ins class="jstree-icon">&nbsp;</ins>
            <a href="/arco/formatos/FO-0002 FormatoAnalisisRequisitos.doc" style="background-image:url('/arco/Menu/images/web.png;');" class="nothing"><ins class="jstree-icon">&nbsp;</ins>
                Análisis de requisitos
            </a>
        </li>

        <li id="1227_1230" class="leaf jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>
            <a href="/arco/formatos/FO-0003 FormatoInstructivoInstalacion.doc" style="background-image:url('/arco/Menu/images/web.png;');" class="nothing"><ins class="jstree-icon">&nbsp;</ins>
                Instructivo de instalación
            </a>
        </li>

        <li id="1227_1231" class="leaf jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>
            <a href="/arco/formatos/FO-0004 FormatoControlCalidadConstruccion.doc" style="background-image:url('/arco/Menu/images/web.png;');" class="nothing"><ins class="jstree-icon">&nbsp;</ins>
                Control de calidad
            </a>
        </li>

        <li id="1227_1232" class="leaf jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>
            <a href="/arco/formatos/FO-0005 FormatoPruebasUsuario.doc" style="background-image:url('/arco/Menu/images/web.png;');" class="nothing"><ins class="jstree-icon">&nbsp;</ins>
                Pruebas de usuario
            </a>
        </li>

        <li id="1227_1233" class="leaf jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>
            <a href="/arco/formatos/FO-0007 FormatoActas-V1.doc" style="background-image:url('/arco/Menu/images/web.png;');" class="nothing"><ins class="jstree-icon">&nbsp;</ins>
                Actas
            </a>
        </li>

        <li id="1227_1263" class="leaf jstree-last jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>
            <a href="/arco/formatos/FO-0006 FormatoSolicitudSoporte V1.doc" style="background-image:url('/arco/Menu/images/web.png;');" class="nothing"><ins class="jstree-icon">&nbsp;</ins>
                Solicitud de soporte
            </a>
        </li></ul>

这就是我构建树的方式;ajax 调用接收一个 html 列表:

$(function () {
    $("#arbolMenu").jstree({ 
        "plugins" : [ "themes", "html_data", "cookies"], 
        "html_data" : {
            "ajax" : {
                "url" : "/arco/CtrlMenu",
                "data" : function (n) {
                    return { id : n.attr ? n.attr("id") : -1 };
                }
            }
        }
    });
}).delegate(".jstree-open>a", "click.jstree", function(event){
    $.jstree._reference(this).close_node(this, false, false);
}).delegate(".jstree-closed>a", "click.jstree", function(event){
    $.jstree._reference(this).open_node(this, false, false);
});
4

2 回答 2

9

与其明确指定图标,不如 使用 jstree 附带的Types Plugin 。然后对于<li>您的 html 中的每个,将其rel属性分配给您定义的类型。这是一个简单的例子:

$(function () {
    $("#demo1").jstree({ 
        "types" : {
            "valid_children" : [ "web" ],
            "types" : {
                "web" : {
                    "icon" : { 
                        "image" : "/arco/Menu/images/web.png" 
                    },
                },
                "default" : {
                    "valid_children" : [ "default" ]
                }
            }
        },
        "plugins" : ["themes","html_data","dnd","ui","types"]
    });
});

这是您的树节点 html 的示例片段:

<li id="1227_1228" rel="web">
    <a href="some_value_here">Mantenimiento planificado</a>
    <!-- UL node only needed for children - omit if there are no children -->
    <ul>
        <!-- Children LI nodes here -->
    </ul>
</li>

由于您rel="web"为您指定<li><li>将接收为 type 定义的属性web,其中包括上面定义的自定义图标。

有关更多信息,您可以查看官方 jstree 文档。

于 2012-08-03T18:23:01.863 回答
0

将以下 CSS 添加到您的文档中:

.jstree-icon {
    display: none;
}
于 2012-08-03T15:48:43.887 回答