记录一次数据整理

·

1 min read

想要透过本地数据排列服务端数据


// 比如以下代码使用row的顺序排列无序的 col 每一行
 const row = [
        { prop: 'peach' },
        { prop: 'Lemon' },
        { prop: 'Pear' },
        { prop: 'avocado' },
        { prop: 'cantaloupe' },
        { prop: 'Banana' }
      ]
      const col = [
        {
          Pear: 12,
          Lemon: 11,
          cantaloupe: 14,
          Banana: 15,
          peach: 10,
          avocado: 13
        },
        {
          Pear: 12,
          Lemon: 11,
          cantaloupe: 14,
          Banana: 15,
          peach: 10,
          avocado: 13
        }
      ]

const result = col.map(v=>{
    const data = {};
    row.some(v2=>{
        data[v2.prop] = v[v2.prop]
    })
return data
}) 

console.log(result)