需要在另一个聚合元素的脚本中动态创建一个名为 offices-list 的聚合元素,如下所示:
然而,一旦到达"document.createElement("offices-list");",这个新标签里的元素就开始渲染了,并且它的on ready方法已经被调用,而我本来希望它们是在我设置属性后发生的。我该怎么办?
编辑:看起来问题的性质不同。我正在将对象设置为属性,而"offices-list"标签没有识别它们,因此不能访问它或循环遍历它。那么,我的问题会变成"如何绑定对象?"
<dom-module id="contacts-tag">
<template>
<iron-ajax ... on-response = "handleResponse"></iron-ajax>
</template>
<script>
Polymer({
is: "contacts-tag",
handleResponse: function(request){
var response = request.detail.response;
this.officesRegions = response.officesRegions;
this.officesCities = response.officesCities;
var dynamicEl = document.createElement("offices-list");
dynamicEl.setAttribute("regions", this.officesRegions);
dynamicEl.setAttribute("cities", this.officesCities);
document.body.appendChild(dynamicEl);
}
});
</script></dom-module>
然而,一旦到达"document.createElement("offices-list");",这个新标签里的元素就开始渲染了,并且它的on ready方法已经被调用,而我本来希望它们是在我设置属性后发生的。我该怎么办?
编辑:看起来问题的性质不同。我正在将对象设置为属性,而"offices-list"标签没有识别它们,因此不能访问它或循环遍历它。那么,我的问题会变成"如何绑定对象?"
attached
回调函数中实现,那么在ready
回调函数中您会做什么呢? - Ümit