简体   繁体   English

单击按钮时刷新 amp-list 内容

[英]Refresh amp-list content on button click

I have a page that generates random numbers for a user.我有一个为用户生成随机数的页面。 On page load, it will generate data and I can handle this much with amp-list.在页面加载时,它会生成数据,我可以使用 amp-list 处理这些数据。 What I want is to have a button where the user can generate new data.我想要的是有一个按钮,用户可以在其中生成新数据。 Think of it like a bingo number generator.把它想象成一个宾果号码生成器。 Page loads and presents the user with a 6. They want a new number, how can this be done?页面加载并向用户显示 6。他们想要一个新号码,如何做到这一点?

I was thinking I could force the page to reload by linking to itself.我在想我可以通过链接到自身来强制页面重新加载。 So the "new number" button would actually just be a url link to the exact same page and this will generate a new number on page load.因此,“新号码”按钮实际上只是指向完全相同页面的 url 链接,这将在页面加载时生成一个新号码。 Using a div with an ID i can provide #randomnumber in the URL and it will go straight to this position.使用带有 ID 的 div 我可以在 URL 中提供#randomnumber,它将 go 直接提供给这个 position。

Im a bit worried about this though as Google might see this as me attempting to inflate viewing numbers to get more ad revenue and what not.我有点担心这一点,因为谷歌可能会认为这是我试图夸大观看人数以获取更多广告收入而并非如此。 Is there a better way to go about this?有没有更好的方法来 go 关于这个?

You can use changeToLayoutContainer to refresh data in amp-list .您可以使用changeToLayoutContainer刷新amp-list数据。 Give it an ID and reference that in your on给它一个 ID 并在你的on

Example:例子:

<button on="list.changeToLayoutContainer()">Show Grid</button>

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

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