1

我有一个数组数组,我想在 a 中使用dom-repeat,但是我收到一个错误,说数据不是数组。

dom-repeat.html:465 dom-repeat 预期数组items,找到 {0: Array(1), 1: Array(1), 2: Array(13)...

订单行项目中的原始数据正在转换为数组数组数据以排序成卡片。我认为理想情况下,模式应该是这样的:

卡父

<template is="dom-repeat" items="[[data]" index-as="index">
  <card-item-group data="[[item]]"></card-item-group> -->
</template>

卡片儿童

<template is="dom-repeat" items="[[data]" index-as="index">
  <card-items data="[[item]]"></card-items> -->
</template>

我是以错误的方式接近这个吗?

我可以通过其他方式将订单项合并到卡片中吗?

原始数据集:

[{
  "0": {
    "time": "2018-02-20",
    "description": "Item 1",
    "number": "1193312"
  },
  "1": {
    "time": "2018-02-21",
    "itemDesc": "Item 2",
    "number": "1193314"
  },
  "2": {
    "time": "2018-02-21",
    "description": "Item 3",
    "number": "1193314"
}

分组数据集:

[{
  "0":[
   {
      "time": "2018-02-20",
      "description": "Item 1",
      "number": "1193312"
    }
  ],
  "1":[
    {
      "time": "2018-02-21",
      "itemDesc": "Item 2",
      "number": "1193314"
    },{
      "time": "2018-02-21",
      "description": "Item 3",
      "number": "1193314"
    }
  ]
}]
4

1 回答 1

1

您的数据不是数组。

像这样对其进行一些转换:

original.map((item) =>
    Object.keys(item).map((key) => item[key]));

这将导致:

[
    [
        {
            "time": "2018-02-20",
            "description": "Item 1",
            "number": "1193312"
        },
        {
            "time": "2018-02-21",
            "itemDesc": "Item 2",
            "number": "1193314"
        },
        {
            "time": "2018-02-21",
            "description": "Item 3",
            "number": "1193314"
        }
    ]
]

然后进行分组...

于 2018-03-22T16:34:17.297 回答