0
比方說,我有對象的數組,它只是有一個id:初始化數組(鏈接響應呼叫者的元素)
[{id:'1'},{id:'2'},{id:'3'}]
,我想有一些業務數據,以填補他們一個個用鐵的Ajax:
<iron-ajax id="initObjectByIdService"
handle-as="json"
on-response="_handleResponse"></iron-ajax>
...
initObjects: function(){
for (var i =0; i < arr.lenght; i++){
this.$.initObjectByIdService.url = <some_url> + '/' + arr[i].id
this.$.initObjectByIdService.generateRequest();
}
},
_handleResponse: function(event){
// How I can link this response event with proper element of an array?
}
什麼可能是有用的是主叫方的元素索引傳遞給on-response
功能,是這樣的:
...
this.$.initObjectByIdService.onResponse = this._handleResponse(i);
...
但它看起來奇怪的錯誤,不工作... :(