1

任何人都告诉我如何在 AMP-list 中解析我的回复。在 AMP 中没有找到任何解决方案如何解析自己的自定义 API 响应。

我的代码。

<div
    class="autosuggest-container hidden"
    [class]="(showDropdown && query) ?
      'autosuggest-container' :
      'autosuggest-container hidden'"
  >
    <amp-list
      class="autosuggest-box"
      layout="fixed-height"
      height="120"
      src="http://lmyadpi.com/api.json?q=a"
      id="autosuggest-list"
    >

      <template type="amp-mustache">
        <amp-selector
          id="autosuggest-selector"
          keyboard-select-mode="focus"
          layout="container"
          on="
            select:
              AMP.setState({
                query: event.targetOption,
                showDropdown: false
              }),
              autosuggest-list.hide"
        >
          {{#results}}
            <div
              class="select-option no-outline"
              role="option"
              tabindex="0"
              on="tap:autosuggest-list.hide"
              option="{{.}}"
            >{{.}}</div>
          {{/results}}
          {{^results}}
            <div class="select-option {{#query}}empty{{/query}}">
              {{#query}}Sorry! We don't ship to your city {{/query}}
            </div>
          {{/results}}
        </amp-selector>
      </template>
    </amp-list>
  </div>
</div>

<amp-state
  id="allLocations"
  src="http://lmyadpi.com/api.json?q=a"
  "emptyAndInitialTemplateJson": [{
            "query": "",
            [[]]
        }]

  ></amp-state>

我的 API 响应:

[[
"1234",
"value2",
""
],
[
"6321123",
"value3",
""
],
[
"43934322",
"value4",
""
],
[
"43660213",
"value5",
""
],
[
"54373228",
"value6",
""
],
[
"410721327",
"value7",
""
]]
4

0 回答 0