2016-03-08 73 views
0

當我的複選框jstree加載完成後,我希望預先打開最後打開的節點(而不是select_node)。 open_node函數似乎只適用於最頂層的父級別節點。我甚至嘗試遍歷節點並調用open_node,它仍然無法工作。我有以下幾種:jstree open_node不能在子節點上工作

// Create instance for checkbox jstree. 
$(function() { 
    $('#myTree').jstree({ 
     "core": { 
      "themes": { 
       'name': 'default', 
       "variant": "small", 
       "icons": false 
      }, 
     }, 
     "checkbox": { 
      "keep_selected_style": false, 
      "three_state": false, 
     }, 
     "plugins": ["checkbox"] 
    }); 
}); 

$("#myTree").bind('ready.jstree', function (event, data) { 
    var $tree = $(this); 
    $($tree.jstree().get_json($tree, { 
     "flat": true 
    })).each(function (index, value) { 
     // lastOpenedNode.value contains the id of the last opened node 
     if (nodeWasLastOpened(this.id) == true) 
      // ONLY OPENS TOP MOST PARENT NODES 
      $("#myTree").jstree().open_node(this.id); 
    }) 
}); 

請幫忙。

回答

1

您可以使用一種私人方法,即_open_to,它將打開所有節點,直至您想要顯示的節點。檢查下面的代碼並演示 - Fiddle

$("#myTree").jstree()._open_to(lastOpenedNode.value); 

if (nodeWasLastOpened(this.id)) 
    $("#myTree").jstree()._open_to(this.id); 
}) 
+0

謝謝,我應該有措辭我的問題更好(由上述編輯)。我其實希望打開多個節點。這很好,但只能使用一次。 – usr4896260

+1

我更新了答案,檢查它是否適用於您 –

+0

我發現了我的問題。我最初將節點id存儲爲字符串,然後將其傳遞給'open_node'函數。一旦我將它轉換爲「int」,該功能就可以完美工作。謝謝。 – usr4896260