我有以下的模板:[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