zoukankan      html  css  js  c++  java
  • es6语法---从提交的数据 找到对应list里面的 键值id 替换--find

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

    case_name: "1111",
    group_id: 23,
    methods: "get",
    re_head: "1111",
    re_path: "1111",
    st_code: "111",
    st_host: "https://test-api-crm-codemaster.codemao.cn/",
    state: ""
    }

    需求: 

    提交的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

  • 相关阅读:
    ubuntu 16.0.5 修改网卡为固定IP
    Ubuntu PostgreSQL安装和配置
    NPOI 1.2.1版本替换为2.4.0版本实体类变更
    C# 之 Math取整
    解决github 下载过慢的问题
    优伦自动语言话务员设置
    python3学习笔记 列表
    【postgresql】role "root" does not exist 解决办法
    Eclipse使用的小技巧
    Servlet
  • 原文地址:https://www.cnblogs.com/kaibindirver/p/14136362.html
Copyright © 2011-2022 走看看