简体   繁体   English

编辑 amp-list 中的数据

[英]Edit data from amp-list

I am making an infinite scroll with amp-list and can not find out how to urlencode (change) received JSON-data values for each page loaded.我正在使用 amp-list 进行无限滚动,但无法找到如何为每个加载的页面对接收到的 JSON 数据值进行 urlencode(更改)。 I do not want server to send both normal encoded string and urlencoded, because this will result in double sized data (200 strings will become 400 for each page).我不希望服务器同时发送普通编码字符串和 urlencoded,因为这将导致双倍大小的数据(每页 200 个字符串将变成 400 个)。 This is my working code for amp-list infinite-scroll:这是我的 amp-list 无限滚动的工作代码:

        <amp-list height="500" width="440" 
        layout="responsive" load-more="auto"
        src="www.myPage.com/firstPageToLoad.json" binding="no">

           <template type="amp-mustache">

              <ul>
                {{#words}} 
                <li>
                    <a class="synWord" href="www.myPage.com/{{.}}">{{.}}</a>    
                </li>
                {{/words}}
              </ul> 

          </template>

        </amp-list> 

So my question is: How can I urlencode "{{.}}" values on client side?所以我的问题是:如何在客户端对“{{.}}”值进行 urlencode? I have read all documentation and can not find any solution.我已阅读所有文档,但找不到任何解决方案。 I have tried to do like this:我试图这样做:

<amp-state id="allData" src="www.myPage.com/firstPageToLoad.json"></amp-state> 

<amp-list [src]="allData.words.map(word => encodeURIComponent(word))"
src="www.myPage.com/firstPageToLoad.json" 
height="500" width="440" 
layout="responsive" load-more="auto" binding="no">

This do not work.这不起作用。 I think its because data is auto-loaded when scrolling and my amp-state is not bind to that event.我认为这是因为滚动时会自动加载数据,而我的 amp-state 未绑定到该事件。

Here comes hacky solution:这是hacky解决方案:

  1. Set binding="always" attribute to amp-list.将 binding="always" 属性设置为 amp-list。
  2. Then in template do this:然后在模板中这样做:

    <a [href]="'http://www.mypage.com/'+encodeURIComponent('{{.}}')">{{.}}</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM