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 @   彳小闲鱼  阅读(508)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· Qt个人项目总结 —— MySQL数据库查询与断言
点击右上角即可分享
微信分享提示