2012-08-03 63 views
6

我需要一个可从数据库配置的jstree,并且对图标有问题(这只是查询中包含图标名称的另一列) 。问题是我无法正确显示它。如何使用html源为jstree设置自定义图标

enter image description here

我通过添加background-image:url('path');属性在<a>标签指向图像建立这个清单,但我不断收到该文件夹​​图标显示(图像不会重复,但我有它的问题easyer可视化)。

如何让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); 
}); 
+0

html是什么样的?这似乎是更多的CSS问题... – Austin 2012-08-03 15:43:48

+0

@奥斯汀我更新了问题。 – Roger 2012-08-03 15:47:05

回答

8

而不是明确指定图标,使用随jstree的Types Plugin。然后,对于您的html中的每个<li>,请将其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文档。

+1

这是从数据库中的任意图标生成的,所以在最坏的情况下,每个节点都可以包含一个不同的图标图标,而不是按类型。我是否必须生成一组网页:{ “图标”:{ “image”:“/arco/Menu/images/web.png” }, },“我第一次加载树? (似乎每个重新加载/导航都很糟糕),我如何让它适用于接收html数据的ajax调用? – Roger 2012-08-03 18:55:28

+0

我更新了我的问题,以显示构造函数,如果这是任何相关 – Roger 2012-08-03 18:58:01

0

添加以下CSS到您的文档:

.jstree-icon { 
    display: none; 
} 
+0

我更新了图像。 '.jstree-icon'类是虚线或箭头。我想保留这些。仍然添加这个不会删除文件夹(我不想保留以防万一我不指定图标) – Roger 2012-08-03 15:55:45

相关问题