On 5 April 2017 at 10:08, <[email protected]> wrote:
> Hello,
>
> I would nest 2 Ajax requests.
>
> I have to make a first request to have the list of commands and go looking
> for the detail of each command with another queries.
>
> But my command displays on outes the records the detail of the last
> command :(
>
> <iron-ajax
> auto
> id="requestRepos"
> url="http://www.xxxxx.fr/api/orders/"
> params='{"ws_key":"XXXXX","filter[current_state]":"9","
> output_format":"JSON"}'
> handle-as="json"
> last-response="{{response}}">
> </iron-ajax>
>
> <template is="dom-repeat" items="[[response.orders]]" as="order">
> <iron-ajax
> auto
> id="requestDetail"
> url="http://www.xxxx.fr/api/orders/{{order.id}}"
> params='{"ws_key":"XXXXXX","output_format":"JSON"}'
> handle-as="json"
> last-response="{{jsondata}}">
> </iron-ajax>
> <div class="card">
> <div class="circle">{{order.id}}</div>
> <div class="header">{{jsondata.order.total_paid_real}}
> €</div>
> </div>
> </template>
>
Nesting is not your issue.
The issue is that you are assigning the output of each repeated iron-ajax
into the same variable (jsondata). This obviously means that only the last
result to be returned is displayed on all instances. The best way to work
this is to extract the content of your dom-repeat into a separate element
that takes a an order id as input and displays the card associated with
that one order id. Then include that element in your dom-repeat so that
there is no shared-state:
<template is="dom-repeat" items="[[orders]]" as="order">
<my-order-element order-id="[[order.id]]"></my-order-element>
</template>
Then your element includes something along the lines of:
<dom-module is="my-order-element">
<template>
<iron-ajax auto id="requestDetail" handle-as="json"
url="http://www.example.com/api/orders/[[orderId]]"
params='{"ws_key":"xxxxxx","output_format":"JSON"}'
last-response="{{orderJson}}">
</iron-ajax>
<div class="card">
<div class="circle">[[orderId]]</div>
<div class="header">[[orderJson.order.total_paid_real]]
€</div>
</div>
</template>
<script>
Polymer({is: 'my-order-element'});
</script>
</dom-module>
--
Daniel Llewellyn
Bowl Hat
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/CABtuYwdHCReftpKC%2BbEYjqP67Oz1gfd-7PinRQfXV7Kg97ZYyw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.