2013-02-18 43 views
1

我正在使用jsTree,至今看起来不错。以特定字开头的开放式树节点

我有节点的ID被用像(G1,G2,G3 ......和像K1,K2,K3一些其他节点)

我可以打开一个特定节点的每个新节点递增列表通过使用

   "core": { 
       "animation": 0, 
       "open_parents": true, 
       "initially_open": ['g1'] 
       }, 

但我要打开与“G”,但不是“K”开头的所有节点文档加载, 是像$(ID^= G)可以用吗?

更新:

的节点通过web服务动态创建像

Dim oSB1 As StringBuilder = New StringBuilder 
oSB1.Append(" <h5 >JSTree</h5> <div id='divtree' ><ul id='tree'> <li id='g1'><a  href='#' class='usr'>1st Node</a><ul> <li><a href='#' rel='file'>1.1</a></li><li><a href='#' class='usr'>1.2</a></li><li><a href='#' class='file'>1.3</a></li></ul></li></ul><ul><li id='g2'><a href='#' class='usr'>2nd Node</a><ul> <li><a href='#' rel='file'>2.1</a></li><li><a href='#' >2.2</a></li></ul></ul> <ul><li id='k2'><a href='#' class='usr'>3rd Node</a><ul> <li><a href='#' rel='file'>3.1</a></li><li><a href='#' >3.2</a></li></ul></ul> <ul><li id='k2'><a href='#' class='usr'>4th Node</a><ul> <li><a href='#' rel='file'>4.1</a></li><li><a href='#' >4.2</a></li></ul></ul></div>") 
Return oSB1.ToString 

从web服务返回的数据被分配给jstree,因此我需要仅打开以'g'开始并且不以'k'开头的节点,在上面的例子中只有2个节点,但想象一下如果有多于100个节点。

的树被称为所以

$("#G2").html(data.d); 
$("#divtree").jstree(
        { 
        "state": "open", 
         "animated": "slow", 
         "plugins": ["themes", "html_data", "ui", "crrm", "contextmenu"], 

         //working 
         "core": { 
          "animation": 0, 
          "open_parents": true, 
          "initially_open": ['g1'] 
         }, 

         "contextmenu": { 
          "items": function ($node) { 
           return { 
            "Create": { 
             "label": "Create a new Node", 
             "action": function (obj) { 
              $("#divtree").jstree("create_node", function() { alert("are you sure?") }, true); 
              this.create(obj); 
             } 
            }, 
            "Rename": { 
             "label": "Rename Node", 
             "action": function (obj) { 
              $("#divtree").jstree("rename_node", function() { alert("you are trying to rename") }, true); 
              this.rename(obj); 

             } 
            }, 
            "Delete": { 
             "label": "Delete Node", 
             "action": function (obj) { 
              $("#divtree").jstree("delete_node", function() { alert("Really!!?") }, true); 
              this.remove(obj); 


             } 
            } 
           }; 
          } 
         } 

        }); 

她唯一的ID为“G1”节点打开,而我想打开所有的节点开始ID为“G” 是有办法让它运行?

回答

0

jsTree非常好,但它的文档确实有点不尽人意。我也努力用了一段时间,终于想出了这一点 - selectively expanding/cotracting jsTree nodes

这可能不是直接回答您的具体问题,但我认为这可能会有帮助。

+0

我仍然不知道如何自定义,根据我的需要:( – jeev 2013-02-18 10:48:58

0

生成json时,只能使用"state" => "open"作为要加载时打开的节点。所以逻辑是在生成json而不是jsTree本身的代码中。

阅读更多doc for json_data plugin

你需要在JSON格式提供数据时应该遵循的基本结构是:

{ 
    "data" : "node_title", // omit `attr` if not needed; the `attr` object gets passed to the jQuery `attr` function 
    "attr" : { "id" : "node_identificator", "some-other-attribute" : "attribute_value" }, // `state` and `children` are only used for NON-leaf nodes 
    "state" : "closed", // or "open", defaults to "closed" 
    "children" : [ /* an array of child nodes objects */ ] 
} 
+0

还有一件事我忘了提到的是节点是在web服务中形成的,而不是在jstree的脚本中,所以他们的id将出现在web服务中 – jeev 2013-02-20 04:15:25

+0

如果节点处于close状态,那么AJAX请求被发送,然后返回的数据被用来渲染/更新jsTree。所以简单地如果你使用上面的设置。数据ma在服务器端完成调用。 – Radek 2013-02-26 23:56:34

+0

谢谢你的回复,但我在哪里添加“状态”:关闭?我的节点是从Web服务中调用的。请参阅更新后的问题 – jeev 2013-02-27 05:56:42

相关问题