标签:tac rip div pre 区分 console 处理 java value
// 数据赋值的简化处理方法: // 1-将后台数据data下的值赋给condition下的data数组下的对象的value值, var condition1 = { data:[ {name:‘***‘, value:‘1‘}, {name:‘****‘, value:‘2‘} ] } var dataSource1 = { name:‘11‘, contactName:‘1122‘ } const dataKey1= [‘aa‘, ‘bb‘]; dataKey1.forEach(function (key, index) { condition1.data[index].value = dataSource1[key] }); console.log(condition1, ‘condition1‘) // { data:[ { name: ‘***‘, value: undefined },{ name: ‘****‘, value: undefined } ] } ‘condition1‘ // 2-将后台数据data下的值赋给condition下的data对象的属性值, var condition2 = { name:‘‘, contactName:‘‘ } var dataSource2 = { name:‘2211‘, contactName:‘2222‘ } const data= [‘name‘, ‘contactName‘]; data.forEach(function (key) { condition2[key] = dataSource2[key] }); console.log(condition2, ‘condition2‘) //{ name: ‘2211‘, contactName: ‘2222‘ } ‘condition2‘ // 3-将后台数据data下的值赋给condition下的data对象的属性值,若属性名称不同 // 可以在设置属性名时以对象形式定义 var condition3 = { name1:‘‘, contactName1:‘‘ } var dataSource3 = { name:‘11‘, contactName:‘22‘ } const dataKey3= [{‘name1‘:‘name‘}, {‘contactName1‘:‘contactName‘}]; dataKey3.forEach(function (item) { for(var key in item){ condition3[key] = dataSource3[item[key]] } }); console.log(condition3, ‘condition3‘) // { name1: ‘11‘, contactName1: ‘22‘ } ‘condition3‘ // 4-将后台数据data下的值赋给condition下的data对象的属性值,若属性名称不同 // 可以在设置属性名时以对象形式定义,两个key区分定义 var condition4 = { name1:‘‘, contactName1:‘‘ } var dataSource4 = { name:‘411‘, contactName:‘422‘ } const dataKey4= [{key1:‘name1‘,key2:‘name‘}, {key1:‘contactName1‘,key2:‘contactName‘}]; dataKey4.forEach(function (item) { condition4[item.key1] = dataSource4[item.key2] }); console.log(condition4, ‘condition4‘) // { name1: ‘411‘, contactName1: ‘422‘ } ‘condition4‘
感谢大神指导~
标签:tac rip div pre 区分 console 处理 java value
原文地址:https://www.cnblogs.com/haimengqingyuan/p/11468540.html