简体   繁体   中英

How to select node by ID in bootstrap tree view?

How to select node by ID in bootstrap tree view? I use bootstrap treeview and fill data by json. I want to search in the tree by ID or data-nodeid attribute in it.

function selectNodeById(id){
    var treeViewObject = $('#tree').data('treeview'),
    allCollapsedNodes = treeViewObject.getCollapsed(),
    allExpandedNodes = treeViewObject.getExpanded(),
    allNodes = allCollapsedNodes.concat(allExpandedNodes);
    for (var i = 0; i < allNodes.length; i++) {
        if (allNodes[i].id != id) continue;
        treeViewObject.selectNode(allNodes[i].nodeId);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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