我想问一下Polymer。当我尝试将数据从ajax传递给子组件时,我无法获取子组件的数据。看起来子组件在父级从ajax获取数据之前已经呈现。这是我的代码:
<template is="dom-bind" id="myId">
<item-list></item-list>
<search-track></search-track>
<promo-banner styling="margin-left: 250px !important;margin-bottom: 50px !important; "></promo-banner>
<template is="dom-if" if="{{data}}"<product-view data="{{data}}"></product-view></template>
<product-recommendation></product-recommendation>
<product-description></product-description>
<info-pengiriman></info-pengiriman>
<info-disclaimer></info-disclaimer>
<mengapa-dekoruma></mengapa-dekoruma>
</template>
<iron-ajax
id="requestProductData"
url="/assets/json/dekoruma.json"
params='{"type":"all"}'
handle-as="json"
on-response="handleResponse">
</iron-ajax>
<script>
Polymer({
is: "product-page",
properties: {
data: {
type: Array
},
productData: {
type: Object
}
},
ready: function () {
this.$.requestProductData.generateRequest();
},
handleResponse: function (data) {
this.data = data.detail.response;
console.log('id',this.id)
for (var i = 0;i<this.data.produk.length;i++){
if (this.data.produk[i].id == this.id){
this.productData = this.data.produk[i];
}
}
console.log(this.productData)
this.$.myId.render()
},
handleUrlName: function (url){
return "../assets/image/"+url;
}
})
</script>