On Mon, 3 Oct 2016 at 14:14 <[email protected]> wrote:
> I am trying to develop a component that makes a variable number of AJAX
> requests, to different URL's. Here is what it does:
>
>
> 1. Make an initial request to get the groups to which the user belongs.
> 2. When the initial request completes, make a request for each group
> returned. The URL for the request includes the group id returned in the
> response to the initial reqest.
> 3. As each group request completes, and the group data to an array
> property.
> 4. When all of the group requests have completed, set a Boolean
> property so that the "loading" indicator becomes hidden.
>
>
Something like this might work:
---- CODE BELOW ----
<iron-ajax auto url="/your/initial/endpoint"
response="{{response}}"></iron-ajax>
<template is="dom-repeat" items="[[response.groups]]">
<iron-ajax auto url="[[_makeUrl(item, index)]]"
on-response="_ajaxResponse"></iron-ajax>
</template>
<div hidden$="[[!_ajaxesComplete]]">
Loading...
</div>
<script>
Polymer({
....
properties: {
....
_responses: {
// used for data handled by part 3.
type: Array,
value: function() { return []; }
},
....
_ajaxesComplete: {
// for part 4.
type: Boolean,
computed: '_doneYet(response.groups, _responses)'
}
....
}
....
_makeUrl: function(item, index) {
// this caters for dynamic urls returned by part 1. for use by part
2.
return '/ajaxUrl/' + item;
},
....
_ajaxResponse: function(e) {
// this does the data handling for part 3.
this._responses.push(e.response);
}
....
_doneYet: function(groups, data) {
// handles part 4.
return groups.length === data.length;
}
....
});
Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups
"Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/polymer-dev/CABtuYwesNJuVYhk0OwQ3ZU9Tz89rXyY5dyLojG34Wxi0vD_T7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.