[英]Polymer. How to reload iron-ajax “onpage show” event?
can you tell me how can i reload an iron-ajax when i opened a page. 您能告诉我打开页面时如何重新加载铁质ajax吗? For example: I have page /news.
例如:我有页面/ news。 When i clicked for this page i am opened element:
当我单击此页面时,我打开了元素:
<dom-module id="my-news">
<template id="app">
<iron-ajax id="ajax_list"
auto
url="http://--------------/books"
last-response="{{data}}"
handleAs="json"
on-response="handleResponse">
</iron-ajax>
<iron-list id="news_list" items="[[data]]">
<template >
<paper-item on-tap="open_news">[[item.name]] </paper-item>
</template>
</iron-list>
</template>
<script>
Polymer({
is: 'my-news',
},
....
</script>
If at this point to add news, the list is not updated. 如果此时要添加新闻,则列表不会更新。 It is updated only when I press F5 and iron-ajax will work again.
仅当我按F5键时,它才会更新,并且Iron-ajax将再次起作用。 I am create a function like this:
我正在创建一个像这样的函数:
ready: function(){
var _this_ = this;
function(){this.ajax_list.generateRequest();}, 5000)
}
But this is not exit 但这不是退出
In order to work, your function need to get the iron-ajax
instance, and for that you need to use this.$
instead of this
. 为了正常工作,您的函数需要获取
iron-ajax
实例,为此,您需要使用this.$
代替this
。 You also need to bind the function with bind(this)
in order to pass the element instance to the callback. 您还需要将函数与
bind(this)
,以将元素实例传递给回调。
Something like that: 像这样:
ready: function(){ var _this_ = this; function(){ this.$.ajax_list.generateRequest() }.bind(this), 5000) },
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.