简体   繁体   English

jstree类型未正确应用

[英]jstree types not applying correctly

I'm attempting to theme a jstree a bit, making the icons fit my needs more appropriately. 我试图主题一点jstree,使图标更适合我的需要。 However, I can't seem to get the types plugin working fully. 但是,我似乎无法让类型插件完全运行。

Creating the tree: 创建树:

// Create JSTree
$('#listbox').jstree({
    "types": {
        "#": {
            "valid_children": ["floor", "default"],
        },
        "default": {
            "valid_children": ["default", "floor"],
            "icon": "/WACH%20Graphics/images/building.png"
        },
        "floor": {
            "icon": "/WACH%20Graphics/images/floor.png"
        }
    },
    "plugins": ["search", "wholerow", "types"]
});

My list is actually generated dynamically. 我的列表实际上是动态生成的。 But, the structure of the unordered list is similar to below: 但是,无序列表的结构类似于以下内容:

<ul>
   <li><a href="building.html">Building 1</a>
      <ul>
          <li rel="floor"><a href="floor.html">Floor1</a></li>
          <li rel="floor"><a href="floor.html">Floor1</a></li>
          <li rel="floor"><a href="floor.html">Floor1</a></li>
      </ul>
   </li>
</ul>

My default icon gets picked up. 我的默认图标被拾取。 But my icon for the "floor" type never gets picked up. 但我的“地板”类型的图标永远不会被拾取。 Instead, everything has the default icon. 相反,一切都有默认图标。

This is jstree 3.0.0. 这是jstree 3.0.0。

The answer as given by the JSTree developer on his Github: JSTree开发人员在他的Github上给出的答案:

The type is not read off of the rel attribute. 该类型不会从rel属性中读取。 Try using 尝试使用

<li data-jstree='{ "type" : "floor" }'... 

in your markup (and keep the single quotes outside, and the double quotes - inside for the data-jstree attribute). 在你的标记中(并将单引号保留在外面,双引号 - 在data-jstree属性中)。

See: https://github.com/vakata/jstree/issues/497 请参阅: https//github.com/vakata/jstree/issues/497

In my case I was just using the types plugin to overwrite the icon. 在我的情况下,我只是使用类型插件来覆盖图标。 Turns out this can be done by simply giving the list item an data-jstree property with an icon property set. 事实证明,这可以通过简单地为列表项提供一个带有图标属性集的data-jstree属性来完成。

<li data-jstree='{ "icon" : "icon.png" }'></li>

Hope someone finds this useful in the future :) 希望有人在将来发现这个有用:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM