You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AMP Mustache模板{{name}}无法渲染JSON响应数据问题排查

问题分析与解决方案

核心原因

amp-list组件默认会直接遍历顶层的JSON数组,但你的服务器响应是一个包含items子数组的对象,模板无法直接定位到数组内的name字段,导致占位符无法渲染数据。

解决方法

在amp-list标签中添加items="items"属性,明确告诉组件要遍历的数据源是响应对象里的items数组:

<amp-list width="auto" height="100" layout="fixed-height" 
      src="https://example.com/index.php?route=information/places/search" 
      [src]="'https://example.com/index.php?route=information/places/search&amp;q=' + query"
      items="items">
<template type="amp-mustache">
    <div class="autocomplete-suggestion" role="button" tabindex="0">
        Name: {{name}}
    </div>
</template>
<div placeholder>Loading...</div>
<div fallback>No results found.</div>
</amp-list>

额外检查项

  1. 确认服务器返回的响应头Content-Type为application/json,AMP对JSON响应的MIME类型有严格校验,非标准类型可能导致解析异常。
  2. 确保amp-list标签已正确闭合(你的原代码片段中缺少闭合标签,需补充)。

内容的提问来源于stack exchange,提问作者Beth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 06:22:08