gpt4 book ai didi

jquery - 如何使用html源为jstree设置自定义图标

转载 作者:行者123 更新时间:2023-12-03 22:32:19 24 4
gpt4 key购买 nike

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

enter image description here

我通过添加 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);
});

最佳答案

不要显式指定图标,而是使用 Types Plugin jstree 附带的。然后对于每个 <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>将收到为类型 web 定义的属性,其中包括上面定义的自定义图标。

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

关于jquery - 如何使用html源为jstree设置自定义图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11798964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com