1. 程式人生 > >JS陣列遍歷-forEach()、map()方法

JS陣列遍歷-forEach()、map()方法

[{a:'1',b:'11'},{a:'2',b:'21'},{a:'3',b:'31'}].forEach((item, index, array) => {
  let c = '';
  let d = '21';
  c = d == item.b ? item : '';
  console.log(c)
})

 

// 列表頁展示
  searchRulesByPage(pageModel: PageModel, searchObj: MchtRuleSearchObj) {
    const _searchObj = ObjectUtils.removeEmptyAttr(searchObj);
    return this.networkService.post({urlStr: '/mchrules/list', body: {...pageModel, ..._searchObj}}).map(res => {
      // 格式化資料 1=> true 0 =》false
      if (res.code === '200') {
        res.data.list.map((val, index, array) => {
          val.status = val.status === '1' ? true : false;
          return val;
        });
      }
      console.dir(res);
      return res;
    });
  }
 // 批量修改商戶規則
  batchEditMchRules(dialogObj, mchs: any[]) {
    // 批量修改
    mchs.forEach((value, index, array) => {
      for (const prop in dialogObj) {
        if (dialogObj.hasOwnProperty(prop) === true) {
          value[prop] = dialogObj[prop];
        }
      }
    });
    // 格式化狀態欄位
    mchs.forEach((value, index, array) => {
      value.status = value.status ? '1' : '0';
    });
    return this.networkService.post({urlStr: '/mchrules/update', body: mchs}).map(res => {
      return res;
    });
  }
 MAINDATASERVICE.get_dossBasicData().then(res => {
          this.options = res['leadsFeedbackReasons'].map((val, index, arr) => {
            return val = Object.assign({},val,{isActive: false});
          });
          console.log('this.options',this.options)
        })