只有2条记录时,我只会看到1条记录。
“解析器响应”映射部分是 $ utils.toJson($ utils.rds.toJsonObject($ ctx.result)[0] [0])
我想出是否要改变:
$utils.toJson($utils.rds.toJsonObject($ctx.result)[0][0])
收件人:
$utils.toJson($utils.rds.toJsonObject($ctx.result)[0][1])
我得到第二条记录,但没有第一条?
Resolver for Query.getdpackByind_subcat, Request mapping template
{
"version": "2018-05-29",
"statements": [
"select * from dpack WHERE ind = '$ctx.args.ind' AND subcat =
'$ctx.args.subcat'"
]
}
Resolver for Query.getdpackByind_subcat, Response mapping template
#if($ctx.error)
$utils.error($ctx.error.message, $ctx.error.type)
#end
$utils.toJson($utils.rds.toJsonObject($ctx.result)[0][0])
从以下位置获取此信息:
https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-rds-
resolvers.html the Query.getPet Resolvers
In the CloudWatch log at the bottom of the Response mapping section
,indicated by the `_____->`, 2 records are returned. However, only 1 was
Transformed, indicated by the `*******>`, why?
"____>records\":[[{\"stringValue\"
:\"bb973271-0091-4b0e-84c4-f1b50fe6517e\"},
{\"stringValue\":\"Government\"},{\"stringValue\":\"Police
Surveillance\"},{\"stringValue\":\"20 pixs\"},{\"longValue\":700},
{\"stringValue\":\"service 20 pixs\"},{\"blobValue\":\"Yi5qcGc=\"}],
[{\"stringValue\":\"d219d0f8-aef7-4a17-bcaf-85504f56494a\"},
{\"stringValue\":\"Government\"},{\"stringValue\":\"Police
Surveillance\"},{\"stringValue\":\"15 picks\"},{\"longValue\":500},
{\"stringValue\":\"service 15 picks\"},
{\"blobValue\":\"YS5qcGc=\"}]]}]}","stash": {},"outErrors": []},
*******>"transformedTemplate": "\n{\"pack_id\"
:\"bb973271-0091-4b0e-84c4-
f1b50fe6517e\",\"price\":700,\"subcat\":\"Police
Surveillance\",\"pack_title\":\"service 20
pixs\",\"ind\":\"Government\",\"content\":\"20
pixs\",\"picture\":\"Yi5qcGc=\"}"
谢谢
答案 0 :(得分:0)
看起来您的查询结果是一个列表。
因此$utils.toJson($utils.rds.toJsonObject($ctx.result)[0][0])
对应于列表的第一项,因此仅返回一个项。
要返回整个列表,应删除第二个数组索引。有关示例,请查看Appsync RDS教程中Query.listPet
的响应映射模板。