從這個鐵的Ajax元素:聚合物嵌套DOM重複預期陣列錯誤
<iron-ajax
id="ajax"
url="..."
handle-as="json"
verbose=true
last-response={{ajaxResponse}}
loading="{{cargando}}">
</iron-ajax>
我得到這個鐵Ajax響應:
{
"id": "3",
"idcontenido": "9",
"imagenes": ["oneimage.png", "anotherimage.png"],
"tipo_imagen": "img-circle",
"html": "Lorem ipsum"
}
,我需要實現一個嵌套的DOM重複結構以迭代來自imagenes屬性的項目。這是我的代碼:
<template is="dom-repeat" items="[[ajaxResponse]]" as="registro">
<template is="dom-repeat" items="[[registro.imagenes]]" as="imagen">
<img class="[[registro.tipo_imagen]]" src="img/[[imagen]]" alt="" width="140" height="140" />
</template>
</template>
但我得到這個錯誤:
[dom-repeat::dom-repeat]: expected array for 'items', found Object {id: "3", idcontenido: "9", imagenes: Array[2], tipo_imagen: "img-circle", html: "Lorem ipsum"}
爲什麼? 謝謝!
您得到的響應不是數組,它的對象和dom-repeat僅適用於數組 – a1626
[\ [dom-repeat :: dom-repeat \]的可能重複:\ items \ ',找到對象](http://stackoverflow.com/questions/40824121/dom-repeatdom-repeat-expected-array-for-items-found-object) – a1626