<iron-ajax auto
url='http://api.fantasy.nfl.com/v1/players/stats'
handle-as="json"
last-response="{{response}}"></iron-ajax>
<template is="dom-repeat" items="{{response}}">
<paper-material class="add-players">
<div class="layout horizontal center">
<h2>{{item.players.name}}</h2> //NOT SURE WHAT SYNTAX SHOULD BE
</div>
</paper-material>
</template>
I am using to return a response from a public API. The problem I have is that the API returns an object and Polymer does not allow us to do a dom-repeat over an object. I am really trying to access an array within that object, is there some way to extract that array from the object returned and do a dom-repeat over that array? If not is there another solution to accessing the response from polymer? Thank you!
You have to use {{response.players}}
instead of {{response}}
in the dom-repeat
. Here is a working demo.
<!DOCTYPE html> <html> <head> <title>paper-scroll-header-panel not working</title> <script src="https://rawgit.com/webcomponents/webcomponentsjs/master/webcomponents.js"></script> <base href="https://cdn.rawgit.com/download/polymer-cdn/1.0.1/lib/"> <link rel="import" href="iron-ajax/iron-ajax.html"> <link rel="import" href="paper-material/paper-material.html"> <!--<link rel="import" href="all-elements.html">--> </head> <body class="fullbleed"> <test-elem></test-elem> <dom-module id="test-elem"> <template> <iron-ajax auto url='http://api.fantasy.nfl.com/v1/players/stats' handle-as="json" last-response="{{response}}"></iron-ajax> <template is="dom-repeat" items="{{response.players}}"> <paper-material class="add-players"> <div class="layout horizontal center"> <h2>{{item.name}}</h2> </div> </paper-material> </template> </template> <script> Polymer({ is : "test-elem" }); </script> </dom-module> </body> </html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.