a543462378 2022-04-19 14:17 采纳率: 82%
浏览 28
已结题

怎么样根据type参数不同把list拆分成不同的数组

项目是react+antd。
现在要根据type=1 2 3,把数组拆分成三个不同的数组,要怎么写?

data: {
  list: [
    {
      quantity: 0.3      receiveCompany: "有限公司"      receiveNumbers: "J134"      shipName: "2号"      state: "0"      taskCompany: "码头"      taskMode: "0"      taskTime: "2021-01-01 09:52:33"      type: "1"
    }{
      quantity: 0.3      receiveCompany: "有限公司"      receiveNumbers: "J1"      shipName: "2号"      state: "0"      taskCompany: "码头"      taskMode: "0"      taskTime: "2021-01-01 09:52:33"      type: "2"
    }{
      quantity: 0.3      receiveCompany: "有限公司"      receiveNumbers: "J1"      shipName: "2号"      state: "0"      taskCompany: "码头"      taskMode: "0"      taskTime: "2021-01-01 09:52:33"      type: "1"
    }{
      quantity: 0.3      receiveCompany: "有限公司"      receiveNumbers: "J1"      shipName: "2号"      state: "0"      taskCompany: "码头"      taskMode: "0"      taskTime: "2021-01-01 09:52:33"      type: "3"
    }{
      quantity: 0.3      receiveCompany: "有限公司"      receiveNumbers: "J1"      shipName: "2号"      state: "0"      taskCompany: "码头"      taskMode: "0"      taskTime: "2021-01-01 09:52:33"      type: "1"
    },
  ]
}
  • 写回答

2条回答 默认 最新

  • 崽崽的谷雨 2022-04-19 14:38
    关注

    循环判断一下 呗 。声明三个数组 。然后 if 判断 符合的就 push

     let list = [
          {
             quantity: 0.3,
             receiveCompany: "有限公司",
             receiveNumbers: "J134",
             shipName: "2号",
             state: "0",
             taskCompany: "码头",
             taskMode: "0",
             taskTime: "2021-01-01 09:52:33",
             type: "1"
          },
          {
             quantity: 0.3,
             receiveCompany: "有限公司",
             receiveNumbers: "J1",
             shipName: "2号",
             state: "0",
             taskCompany: "码头",
             taskMode: "0",
             taskTime: "2021-01-01 09:52:33",
             type: "2"
          },
          {
             quantity: 0.3,
             receiveCompany: "有限公司",
             receiveNumbers: "J1",
             shipName: "2号",
             state: "0",
             taskCompany: "码头",
             taskMode: "0",
             taskTime: "2021-01-01 09:52:33",
             type: "1"
          },
          {
             quantity: 0.3,
             receiveCompany: "有限公司",
             receiveNumbers: "J1",
             shipName: "2号",
             state: "0",
             taskCompany: "码头",
             taskMode: "0",
             taskTime: "2021-01-01 09:52:33",
             type: "3"
          },
          {
             quantity: 0.3,
             receiveCompany: "有限公司",
             receiveNumbers: "J1",
             shipName: "2号",
             state: "0",
             taskCompany: "码头",
             taskMode: "0",
             taskTime: "2021-01-01 09:52:33",
             type: "1"
          },
       ];
    
       let arr1 = [];
       let arr2 = [];
       let arr3 = [];
       list.map((item) => {
          if (item.type && item.type == 1) {
             arr1.push(item);
          } else if (item.type && item.type == 2) {
             arr2.push(item);
          } else {
             arr3.push(item);
          }
       });
       console.log(arr1,arr2,arr3)
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月27日
  • 已采纳回答 4月19日
  • 创建了问题 4月19日

悬赏问题

  • ¥15 SPSS分类模型实训题步骤
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。