elementUI select multiple 默认选中
需求 后端返回几个id,select 默认选中后端返回的格式 tag: ‘1,2,3,4’//这些是id这个options数据格式let tagslist = [{name:'vue',id:1,},{name:'node',id:2,},{name:'react',id:3,},...
·
需求 后端返回几个id,select 默认选中
后端返回的格式 tag: ‘1,2,3,4’ // 这些是id
这个options数据格式
let tagslist = [
{
name:'vue',
id:1,
},
{
name:'node',
id:2,
},
{
name:'react',
id:3,
},
{
name:'ng',
id:4,
}
]
如何默认选中这些数据
- value-key 和 value的配合使用
- 这个tag的数据(后端给前端返回是 ‘1,2,3,4’ 这个字符串),前端需要处理这个数据
let data = [];
let tag = this.ruleForm.tag.split(",");
tagslist.forEach(item => {
tag.forEach(code => {
if (item.id == code) {
data.push(item);
}
});
});
this.ruleForm = {
...this.ruleForm,
tag: data
};
更多推荐
已为社区贡献33条内容
所有评论(0)