js vue数据回显函数封装(字典翻译)

//值和id的名字需要和回显函数的值和id对应

//数据格式(该案例值为:dictValue;id为:dictLabel)

deptList: [

{ dictValue: 2, dictLabel: '移动' }, { dictValue: 3, dictLabel: '联通' },

{ dictValue: 4, dictLabel: '电信' }, { dictValue: 1, dictLabel: '铁塔' }],

 

//方法:

selectDictLabel(datas, value) {//datas放数组 //value放值

var actions = [];

Object.keys(datas).some((key) => {

if (datas[key].dictValue == ('' + value)) { //dictValue为数据的值

actions.push(datas[key].dictLabel);//dictLabel为数据的id

return true; }

})

return actions.join('');

}

 

//调用案例

let res = this.selectDictLabel(this.deptList, 2)

console.log(res)//打印结果为 ‘移动’

 

posted @ 2022-02-23 15:21  彳小闲鱼  阅读(488)  评论(0编辑  收藏  举报