javascript - 如何在 Bootstrap TreeView 中按ID选择节点?

标签 javascript jquery twitter-bootstrap treeview

如何在 Bootstrap TreeView 中按 ID 选择节点? 我使用 bootstrap treeview 并通过 json 填充数据。我想通过树中的 ID 或 data-nodeid 属性在树中搜索。

最佳答案

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);
    }
}

关于javascript - 如何在 Bootstrap TreeView 中按ID选择节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51731433/

相关文章:

html - Bootstrap 在移动 View 中重新排序图像和文本

javascript - 如何指定时区,以便时刻给出该时区的正确日期?

javascript - ExtJS 为什么多个ajax请求互相等待

jquery - 当选择名称相同但值不同的情况下禁用同级元素

css - Bootstrap 显示字段信息

twitter-bootstrap - 摆脱 Twitter Bootstrap 缩略图边框

javascript - 如何反转 javascript Uint32 中的字节顺序

javascript - 小书签如何处理跨源请求 - 是否需要 cors?

c# - C# 中的切换按钮

javascript - 使用 AJAX 更新 Div 结果丢失更新