关联表字段回显在多选框中
作者:互联网
<uni-forms-item name="riskclass" label="风险类别" required>
<uni-data-checkbox multiple :localdata="riskclasses" v-model="formData.riskclass" />
</uni-forms-item>
onLoad(e) {
const id = e.id
this.formDataId = id
this.getDetail(id)
this.loadriskclasses()
},
loadriskclasses() {
db.collection('risk-class').limit(500).get().then(res => {
const riskclasses = []
this.riskclasses = res.result.data.map(item => {
riskclasses.push(item.riskclass_id)
return {
value: item.riskclass_id,
text: item.riskclass_name
}
})
}).catch(err => {
uni.showModal({
title: '提示',
content: err.message,
showCancel: false
})
})
}
关键点:
this.riskclasses = res.result.data.map(item => {
riskclasses.push(item.riskclass_id)
return {
value: item.riskclass_id,
text: item.riskclass_name
}
map数组中的数据,riskclass_Id是从数据库中获取到的数据中的riskclass_Id字段,显示文字riskclass_name对应的是类别表的对应显示。
标签:map,回显,riskclasses,res,表字,riskclass,item,id,选框 来源: https://blog.csdn.net/wenxi2367/article/details/118941995