bootstrap-treeview 默认选中根节点报错Cannot read property 'length' of undefined

zhenye1986 2018-08-10 02:37:59
$.ajax({
type: "Post",
url: "componentTreeJson.action",
dataType: "json",
success: function (result) {

var treeData = [
{
text: "new Component",
id:0
}
];

if (null == result){
result = treeData;
}

rootId = result[0]["id"];

var tt = $('#tree').treeview({
data: result, // 数据源
showCheckbox: false, //是否显示复选框
highlightSelected: true, //是否高亮选中
nodeIcon: 'glyphicon glyphicon-cog', //节点上的图标
multiSelect: false, //多选
showBorder: false,
levels: 99,
onNodeSelected: function (event, data) {
showDataList(data.id);
}
});

var node = $('#tree').treeview('findNodes', [rootId, 'text']); //这里报错了,Cannot read property 'length' of undefined
$('#tree').treeview('selectNode', [ node[0], { silent: true } ]);


},
error: function () {
alert("树形结构加载失败!")
}
});
...全文
521 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
nathanlw 2021-04-08
  • 打赏
  • 举报
回复
解决了吗?
zhenye1986 2018-08-10
  • 打赏
  • 举报
回复
var node = $('#tree').treeview('findNodes', [rootId, 'id']); 报错
zhenye1986 2018-08-10
  • 打赏
  • 举报
回复
确认数据源是没有问题的,只是无法默认选中根节点

87,993

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧