js 数组元素(元素也为数组)在另个数组中取值(字典方案)

数据格式:

[

{

color: "",
companyName: "济南宏益环境科技有限公司",
orgid: "370114,3701",
remark: "111",
tag: "人工标记"

},
……

]

 

字典:

export const districtData = [
    { key: "3701", title: "市辖区", value: "3701" },
    { key: "370102", title: "历下区", value: "370102" },
    { key: "370103", title: "市中区", value: "370103" },
    { key: "370104", title: "槐荫区", value: "370104" },
    { key: "370105", title: "天桥区", value: "370105" },
    { key: "370112", title: "历城区", value: "370112" },
    { key: "370113", title: "长清区", value: "370113" },
    { key: "370124", title: "平阴县", value: "370124" },
    { key: "370125", title: "济阳县", value: "370125" },
    { key: "370126", title: "商河县", value: "370126" },
    { key: "370114", title: "章丘市", value: "370114" },
    { key: "370116", title: "莱芜区", value: "370116" },
    { key: "370117", title: "钢城区", value: "370117" },
    { key: "370190", title: "高新区", value: "370190" },
]
 
需求:
将数据结构中orgid字段(该字段为单个或者多个字,均为字符串形式),根据本地字典转换成对应的title
 for (let i of this.tableData) {
                        const tempORgid = i.orgid.split(',')//['370105','370113']
                        i.orgid = [...new Set(tempORgid)]//后端返回的orgid有重复的,需要去重
                        i.quxian = i.orgid.map(item=>
                            this.districtData.find(it => it.value===item).title).join('; ')
                    }

               
 
posted @ 2022-08-31 17:07  赵辉Coder  阅读(431)  评论(0编辑  收藏  举报