问题描述
想要用el-tree做一个默认选中节点的东西,怎么实现。数据是从后台传的。
数据格式:
"id": "-1",
"text": "顶级节点",
"icon": null,
"state": {
"opened": true
},
"checked": true,
"attributes": null,
"children": [
{
"id": "1ad7d4d1-0fef-b9ee-44cd-0165a289303e",
"text": "节点1",
"icon": null,
"state": {
"selected": false
},
"checked": false,
"attributes": null,
"children": [
我尝试着做过,不过现在有两个问题
1:目前只能先设定一个如下格式的data,用来接收数据
treeData: [
{
id: "",
text: "",
children: []
}
],
在
axios.get(url).then(res => {
this.treeData[0].id = res.data.id;
this.treeData[0].text = res.data.text;**
this.treeData[0].children = res.data.children;**
})
数据是这样接收的,希望做到的是能够
this.treeData = res.data;
但是这时候treeData数据格式为object,但el-tree接收的data为array格式。
但是不知道你res.data.children的数据格式是否符合树形结构,如果符合可以这样做
设置默认展开的前提是设置了node-key
你要么没有设置node-key,要么提供的选中数组中的值与各个节点的node-key不一致