正常写法

  1. // 课程数据处理
  2. const courseFormat = (item) => {
  3. return {
  4. productId: item.id,
  5. title: item.title,
  6. coverUrl: item.coverUrl,
  7. simpleDesc: item.simpleDesc,
  8. isFree: item.salePrice === 0,
  9. salePrice: item.salePrice || 0,
  10. originalPrice: item.originalPrice || 0,
  11. viewCount: item.studentNum
  12. }
  13. }
  14. const courseListNew = courseList.map((item) => courseFormat(item))
  15. const courseListFormat = injectRowKey(courseListNew)

courseList.map((item) => courseFormat(item))
如果只有一个item,那么就可以进行简写,如果需要用到index,则不可简写

简写

  1. // 课程数据处理
  2. const courseFormat = (item) => {
  3. return {
  4. productId: item.id,
  5. title: item.title,
  6. coverUrl: item.coverUrl,
  7. simpleDesc: item.simpleDesc,
  8. isFree: item.salePrice === 0,
  9. salePrice: item.salePrice || 0,
  10. originalPrice: item.originalPrice || 0,
  11. viewCount: item.studentNum
  12. }
  13. }
  14. const courseListFormat = injectRowKey(courseList.map(courseFormat))

此为简写方式:
courseList.map(courseFormat)