eltree ref什么时候有_Element Ui Tree树形控件中动态设置已选中项

[js]

data() {

return {

resourceData: [],//数组,我这里是通过接口获取数据,

resourceDialogisShow: false,

resourceCheckedKey: [],//通过接口获取的需要默认展示的数组 [1,3,15,18,…]

resourceProps: {

children: "subArr",

label: "chineseName"

}

};

},

methods: {

getKey(id) {

let that = this;

let params = {

roleId: id

};

that.$get(this.$api.getConfigure(), params, function (res) {

if (res.code == "0000") {

if (res.result) {

let data = res.result;

let arr = [];

for (let item of data) {

arr.push(item.id)

}

that.$refs.tree.setCheckedKeys(arr);//获取已经设置的资源后渲染

}

}

});

}

}

[/js]

名词解释

这里照搬官网的说明。

Attributes

参数

说明

类型

可选值

默认值

default-expanded-keys

默认展开的节点的 key 的数组

array

props

参数

说明

类型

可选值

默认值

label

指定节点标签为节点对象的某个属性值

string, function(data, node)

children

指定子树为节点对象的某个属性值

string

方法

方法名

说明

参数

setCheckedKeys

通过 keys 设置目前勾选的节点,使用此方法必须设置 node-key 属性

(keys, leafOnly) 接收两个参数,1. 勾选节点的 key 的数组 2. boolean 类型的参数,若为 true 则仅设置叶子节点的选中状态,默认值为 false

划重点

ref="tree" 这个一定要设置,不然你会发现打印this.$refs.tree 为undefined,并且也没法调用setCheckedKeys方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值