当前位置:网站首页>数组对象拼串
数组对象拼串
2022-04-22 17:12:00 【時間不夠以後】
数组对象拼串
var objs = [
{
"id": 445,
"pubId": 22,
"propName": "MQ类型",
"propCode": "mqType",
"defaultValue": "1",
"memo": ""
}, {
"id": 446,
"pubId": 22,
"propName": "MQ主题",
"propCode": "mqTopic",
"defaultValue": "",
"memo": ""
}
]
// 拼串生成 {"MQ类型":"mqType","MQ主题":"mqTopic"}
// var idsStr = objs.map(function(obj,index){
// return obj.propName + ":" + obj.propCode
// }).join(",")
// console.log(idsStr)
const res = {
}
objs.forEach(e => {
res[e.propName]=e.propCode
})
console.log(res)
var parameters = {
"同步终端类型": "dbVender",
"dubbo地址": "dubboRegistryAddr"
}
/* 目标数据格式: [ { "propName": "同步终端类型", "propCode": "dbVender", }, { "propName": "dubbo地址", "propCode": "dubboRegistryAddr", } ] */
let brr = []
for (let key in parameters) {
brr.push({
'propName': key,
'propCode': parameters[key]
})
}
console.log(brr)
// 用于新增一行表单数据
var temp = {
'propName': '',
'propCode': ''
}
brr.push(temp)
console.log(brr)
这个用于下拉框select时,默认只有id,但是还想获取name时用。
var type = [
{
"id": 19,
"pubName": "数据库",
"pubClazz": "12334",
"memo": "数据库1"
},
{
"id": 21,
"pubName": "数据中心",
"pubClazz": "343234",
"memo": "数据中心2"
},
{
"id": 22,
"pubName": "Kafka管道",
"pubClazz": "5677",
"memo": "kafka"
}
]
var id = 19
type.forEach(e => {
if (e.id === id) {
console.log(e.pubName)
}
})
拿到的一个number值,要转换为数组[ ]显示。
// html, 当前拿到的dtsTaskDo.taskType是一个 1-9 的 number值
<FormItem prop="dtsTaskDo.taskType" label="任务类型" multiple>
<Select v-model="currentType" multiple @on-change="get_num">
<Option v-for="item in dtsTaskTypes" :value="item.value" :label="item.label" :key="item.value"></Option>
</Select>
</FormItem>

// 方法1
let map = {
'1': [1],
'2': [2],
'3': [1, 2],
'4': [4],
'5': [1, 4],
'6': [2, 4],
'7': [1, 2, 4]
}
this.currentType = map[this.form.dtsTaskDo.taskType]
// 方法2
// switch (this.form.dtsTaskDo.taskType) {
// case 1:
// this.currentType = [1]
// break
// case 2:
// this.currentType = [2]
// break
// case 3:
// this.currentType = [1, 2]
// break
// case 4:
// this.currentType = [4]
// break
// case 5:
// this.currentType = [1, 4]
// break
// case 6:
// this.currentType = [2, 4]
// break
// case 7:
// this.currentType = [1, 2, 4]
// break
// default:
// break
// }
// 其中下拉的值为:
DTS_TASK_TYPES = [
// 1: 全量 2: 增量 4: 比对 (如果为组合,则进行相加,顺序为 全量 -> 增量 -> 比对)
// {
// label: '存量增量',
// value: 3
// },
{
label: '存量迁移',
value: 1
},
{
label: '增量同步',
value: 2
},
{
label: '数据比对',
value: 4
}
]
同上,拿到的任务类型值为 1-9 的number 值,需要在表格中显示为拼串后的label值。

let taskTypeLabel = ''
const taskTypeArray = {
1: [1],
2: [2],
3: [1, 2],
4: [4],
5: [1, 4],
6: [2, 4],
7: [1, 2, 4]
}
// 方法一 n+n
let temp = {
}
DTS_TASK_TYPES.forEach(element => {
temp[element.value] = element.label
})
console.log(temp)
taskTypeLabel = taskTypeArray[params.row.taskType].map((v, i, arr) => {
return temp[v]
}).join('/')
// 方法二 n*n
// taskTypeLabel = taskTypeArray[params.row.taskType].map((v, i, arr) => {
// for (const element of DTS_TASK_TYPES) {
// if (element.value === v) {
// return element.label
// }
// }
// }).join('/')
版权声明
本文为[時間不夠以後]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43972213/article/details/106408062
边栏推荐
- MySQL笔记(基础篇)
- Why do you have to override the hashcode method to override the equlas method
- GlobalMapper20 如何批量把dwg文件转换为dxf文件,效率神器
- swagger Authorization测试
- 2022年环境影响评价工程师考试评价技术方法练习题及答案
- 华为走在老路上
- [golang] force buckle leetcode - 657 Whether the robot can return to the origin (simulation)
- 7 Questions d'entrevue sur la fermeture
- Jiaoxia is following the old path of perfect diary
- 基于深度学习的日志数据异常检测
猜你喜欢

Knowing that it is listed in Hong Kong, it is the first Chinese concept stock to return to Hong Kong with dual main listing

The most expensive new shares in 2022 are coming. Xiaomi and Huawei earn 10 times

KNN and K-means from introduction to actual combat

SDN学习之Opendaylight浅析(一)

《KNN与K-means从入门到实战》

Opendaylight analysis of SDN learning (3)

Jupyter notebook内使用(添加)虚拟环境

Distributed (III) -- realize distributed lock

leetcode:23. 合并K个升序链表

2022年环境影响评价工程师考试相关法律法规练习题及答案
随机推荐
Knowing that it is listed in Hong Kong, it is the first Chinese concept stock to return to Hong Kong with dual main listing
使用AppCube,零门槛快速搭建5G消息服务号
Apache配置多端口
2022最贵新股来了,小米、华为小赚10倍
MySQL索引底层原理
正则匹配URL
MySQL配置sql_mode
写LeetCode发现的一些神奇语句
怎样高效管理混合云中的数据?
ES6 对象扩展 链判断运算符 和 Null判断运算符
SaaS 长河下,AfterShip 技术升级的“加减法”
Minimum number of jumps at home - C language DFS
MySQL_ 00_ Get to know MySQL
Vscode plug-in package migration and specified location
MATLAB---非线性优化问题二
MATLAB---回归分析
Regular matching URL
2022年环境影响评价工程师考试技术导则与标准练习题及答案
KNN and K-means from introduction to actual combat
关于闭包的7道面试题