我有以下的模板:[DOM重複:: DOM的重複]:用於`items`預期陣列,發現對象
<iron-ajax
id="ajax"
url="backend/api.php?operacion=contenidos&idf=[[datos.id]]&len=[[len]]"
handle-as="json"
verbose=true
last-response={{ajaxResponse}}
loading="{{cargando}}"> </iron-ajax>
<template is="dom-repeat" items="[[ajaxResponse]]">
Ajax響應包含以下JSON(正確):
{
"1": [{
"id": "6",
"idfolleto": "1",
"fila": "1",
"orden": "1",
"tipo": "carrousel",
"titulo": "",
"subtitulo": null,
"color1": null,
"color2": null,
"color_fondo": null
}],
"2": [{
"id": "7",
"idfolleto": "1",
"fila": "2",
"orden": "1",
"tipo": "texto-imagenes",
"titulo": "Texto 1",
"subtitulo": null,
"color1": null,
"color2": null,
"color_fondo": null
}, {
"id": "8",
"idfolleto": "1",
"fila": "2",
"orden": "2",
"tipo": "texto-imagenes",
"titulo": "Texto 2",
"subtitulo": null,
"color1": null,
"color2": null,
"color_fondo": null
}],
"3": [{
"id": "9",
"idfolleto": "1",
"fila": "3",
"orden": "3",
"tipo": "texto-imagenes",
"titulo": "Texto 3",
"subtitulo": null,
"color1": null,
"color2": null,
"color_fondo": null
}]
}
但我得到一個錯誤:
[dom-repeat::dom-repeat]
: expected array foritems
, foundObject {1: Array[1], 2: Array[2], 3: Array[1]}
爲什麼? 謝謝!
該錯誤消息是正確的 - 「根對象」 不是陣列(即,由包裹'[]'),但對象(通過'{}'包裹) – ain
但其他類似對象的類似服務響應,由{}封裝,它正在工作 – Jaime
@Jaime我已將您的PHP代碼移動到您的新[tag:php]問題中。 – tony19