![](/img/trans.png)
[英]polymer iron-ajax : How to Bind data from input element to iron-ajax's body attribute
[英]How can I create a repeating element from data received from <iron-ajax>?
<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>
我用来从公共API返回响应。 我的问题是API返回了一个对象,而Polymer不允许我们对一个对象进行dom-repeat。 我真的在尝试访问该对象中的数组,是否有某种方法可以从返回的对象中提取该数组并对该数组进行dom-repeat? 如果不是的话,还有没有其他方法可以访问聚合物的响应? 谢谢!
您必须在dom-repeat
使用{{response.players}}
而不是{{response}}
。 这是一个工作示例。
<!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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.