关闭/打开父节点后,JSTree保留节点样式

时间:2016-07-21 21:25:57

标签: jquery jstree

我使用JSTree实现了简单的树,我需要使用JQuery更改特定的节点样式,我的问题是当关闭父节点并再次打开它时,该节点上的更改将被丢弃,

这是一个包含我的代码的jsFiddle:

<div id="stations_tree">
  <ul>
    <li>root1</li>
    <li>root2</li>
    <li>root3
      <ul>
        <li id="child1">child1</li>
        <li id="child2">child2</li>
      </ul>
    </li>
  </ul>
</div>

<input type="button" id="btn" value="Change color"/>
<script>
    $(document).ready(function(){
    $('#stations_tree').jstree({
        "plugins" : [ "types" ], 
        "types" : {
            "default" : {
                "icon" : "fa fa-circle"
            },
            "station" : {
                "icon" : "fa fa-circle"
            }
        }, 
        "core" : {
            "multiple" : false
        }
    }).bind("open_node.jstree close_node.jstree", function (e, data) {

    });

    $("#stations_tree").jstree("open_all");
});  

$("#btn").click(function(){
    $("#child1").css("color","green");
});
</script>

https://jsfiddle.net/m_kaleia/vdbb0hdx/

如何在重新打开父节点后保留节点样式?

0 个答案:

没有答案