聚合物通过自定义元素的路由数据未定义
问题描述:
我试图将应用路由的参数传递给未定义的自定义元素。我可以在文件中显示该参数,但在自定义元素中,它没有定义。以下是我的代码,请帮助我检查如何修复它。谢谢。聚合物通过自定义元素的路由数据未定义
在自定义元素文件中,getid
没有定义。
我的文件
<app-route
route="[[route]]"
pattern="/:slug/:id"
data="{{routeData}}"></app-route>
<!-- display correctly -->
[[routeData.id]]
<myelement-http-get
id="getCategoryData"
getid="[[routeData.id]]"
geturl="http://localhost:9000/polymer/category/"
jsonobject="{{jsonobject}}"
failure="{{failure}}"></myelement-http-get>
自定义元素
<script>
Polymer({
is: 'myelement-http-get',
properties: {
geturl: String,
getid: String,
jsonobject: {
type: Object,
notify: true
},
failure: {
type: Boolean,
notify: true,
readOnly: true
}
},
ready: function() {
/* undefined found this.getid */
this.$.ajaxData.url = this.geturl + this.getid;
this.$.ajaxData.generateRequest();
},
handleResponse: function (data) {
this.jsonobject = data.detail.response;
}
});
</script>
答
的数据绑定getid
和geturl
效应发生的ready
后的回调,所以这不是你会想操纵这些属性。
相反,您应该使用complex observer来观察getid
和geturl
。只有在定义和更改了这两个属性时,才会调用此观察者(此行为在Polymer 2.0中稍有变化)。
你应该从ready
删除更改,并添加复杂的观察者像如下所示:
感谢,这是部分正确。但是'观察者:['_generateRequest(geturl,getid)']'当我得到第三页时不能更新。 'geturl'总是显示第二页网址。 – ppshein