后端,发来的数据,大概长这样
页面内容
item4.serveBy是一个数字,
然后为了查这个数字,对应的用户名字,然后显示
<view>{{userDictionary(item4.serveBy) || ""}}</view>
//字典,获取,翻译
import { getDicts,selectDictLabel } from "@/api/system/dict/data.js";
computed:{
//用户字典
userDictionary(){
return (dataNum) => {
return selectDictLabel(this.dictSys_user,dataNum);
}
}
}
字典dict.js内容
// 根据字典类型查询字典数据信息
export function getDicts(dictType) {
return uni.$u.http.get('/system/dict/data/type/' + dictType)
}
// 回显数据字典
export function selectDictLabel(datas, value) {
if (value === undefined) {
return "";
}
var actions = [];
Object.keys(datas).some((key) => {
if (datas[key].dictValue == ('' + value)) {
actions.push(datas[key].dictLabel);
return true;
}
})
if (actions.length === 0) {
actions.push(value);
}
return actions.join('');
}