我在Polymer 1.0.2中遇到了铁-ajax和数据绑定的问题.Polymer文档中的一个稍微改变的例子都没有起作用.
以下是我的更改代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../bower_components/iron-ajax/iron-ajax.html">
</head>
<body>
<template is="dom-bind">
<iron-ajax
auto
url="http://jsonplaceholder.typicode.com/posts/"
lastResponse="{{data}}"
handleAs="json">
</iron-ajax>
<template is="dom-repeat" items="{{data}}">
<div><span>{{item.id}}</span></div>
</template>
</template>
<script>
(function (document) {
'use strict';
var app = document.querySelector('#app');
window.addEventListener('WebComponentsReady', function() {
var ironAjax = document.querySelector('iron-ajax');
ironAjax.addEventListener('response', function() {
console.log(ironAjax.lastResponse[0].id);
});
ironAjax.generateRequest();
});
})(document);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我改变的只是输入一个URL以获得真正的JSON响应并设置auto和handleAs属性.我还添加了一个带有侦听器的小脚本,用于响应事件.侦听器工作正常并处理响应,但dom-repeat模板中的跨距不会呈现.
我正在使用Polymer 1.0.2和铁元素1.0.0
| 归档时间: |
|
| 查看次数: |
12190 次 |
| 最近记录: |