如何从从<iron-ajax>接收的数据创建重复元素
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>
相关文章:
- 使用外部数据创建仪表板(谷歌电子表格)-JavaScript
- 从html表中的输入数据创建图表
- 使用来自不同循环Javascript的数据创建数组
- 在d3forjavascript中,如何为数据创建不同的元素
- 如何使用json数据创建下拉列表
- 使用 mysql 数据创建条形图
- 在javascript中使用给定的数据创建Json
- Jquery:为新数据创建寻呼机(next-prev按钮)
- 为Meteor数据创建编号列表
- 如何创建和下载PDF和docx格式的文件,该文件将从AngularJS中的表中的数据创建
- 为数据创建唯一变量
- 如何使用旧数组中的数据创建新数组
- 使用外部数据创建体式任务
- 将数据从一个工作表复制到另一个工作表;使用目标工作表中的复制数据创建一个表
- 我可以在谷歌地图上使用OpenStreetMap数据创建获取路线吗?如何
- 如何为具有嵌套对象的 JSON 数据创建 Mustache 模板
- 如何使用 import.io 中的数据创建 Web 应用
- 从 CSV 数据创建 D3.js 可折叠树
- 如何使用SQLite数据创建Javascript var
- 使用 AJAX 数据创建注释页选择