比对的数据:
targetlist=[ { "id": 1, "host": "https://test-api-crm-codemaster.codemao.cn/" }, { "id": 2, "host": "https://test-api-marketing.codemao.cn/" } ]
 
提交的数据:
values=
{

}

 

需求: 

提交的st_host 字符 找到 targetlist对应的id 替换

 

const newValues = {...values} // 解构values,将原form的values形成一个新的对象newValues
newValues.st_host = this.hosts.find(t => t.id === Number(values.st_host)).host // 利用es6数组的find函数找到对应id的item,将该item的host赋值给st_host
 
红色那坨等于下面的写法:
let host = ''
this.hosts.forEach((item, index) => {
if (item.id === Number(values.st_host)) {
  host = item.host
 }
})
 
等于下面这坨

var inventory = [
{name: 'apples', quantity: 2},
{name: 'bananas', quantity: 0},
{name: 'cherries', quantity: 5}
];

function findCherries(fruit) {
return fruit.name === 'cherries';
}

console.log(inventory.find(findCherries));

 

 

https://www.cnblogs.com/amujoe/p/8875053.html

https://www.cnblogs.com/ChineseLiao/p/11638175.html

相关文章:

  • 2022-12-23
  • 2021-10-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案