我想在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"
}
]
}]
答案 0 :(得分:1)
您的数据不是数组。
对它进行一些改造:
func testAllowed() {
// Create the worker.
let worker = Worker()
// Because `Worker` has been extended to conform to `CodeCopStub`, it will
// have this static property. Set it to true to cause
// `shouldAllowExecution()` to return `true`.
Worker.allowed = true
// Call the method and get the result.
let actualResult = worker.doSomeStuff()
// Make sure the result was correct.
let expectedResult = "Cop allowed it"
XCTAssertEqual(expectedResult, actualResult)
}
func testNotAllowed() {
// Same stuff as last time...
let worker = Worker()
// ...but you tell it not to allow it.
Worker.allowed = false
let actualResult = worker.doSomeStuff()
// This time, the expected result is different.
let expectedResult = "Cop said no"
XCTAssertEqual(expectedResult, actualResult)
}
这将导致:
original.map((item) =>
Object.keys(item).map((key) => item[key]));
然后进行分组......