JsTree中提示:Cannot read property 'core' of underfined

场景

Jstree的树形结构正好好运行,给数据添加了禁用状态后,就提示:

JsTree中提示:Cannot read property 'core' of underfinedJsTree中提示:Cannot read property 'core' of underfined

在仔细比对代码没错订单情况下,猜测是数据原因。

实现

因为添加了是否禁用状态,首次进入页面时默认加载启用的数据,但是启用的数据中可能会有pid(即父节点i)被禁用的场景。

就会出现如下这种:

查询返回的数据中pid属性在id中不存在。

JsTree中提示:Cannot read property 'core' of underfinedJsTree中提示:Cannot read property 'core' of underfined

解决:

将数据库中禁用的数据先启用,首次访问时默认查询全部数据。最终使pid的属性值都存在。