好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

【React】遍历的两种方式

1、foreach(推荐)

   list.forEach((item)=>{
  
    });
eg:
 dataSource.forEach((item) => {
      const est = item.estimateAmount === null ? 0 : parseFloat(item.estimateAmount);
      const gmv = item.estimateGmv === null ? 0 : parseFloat(item.estimateGmv);
      allCountBudget += est;
      allCountGmv += gmv;
      // allCountGmv = parseFloat(allCountGmv) + parseFloat(gmv);
    });
 

2、map(内部不支持计算逻辑?)

 list.map((item, index)=>
        <div>
          {item.name}
        </div> 
      )
    ) 

 

查看更多关于【React】遍历的两种方式的详细内容...

  阅读:36次