[英]Polymer iron-ajax data binding example not working
我在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>
我改變的只是輸入一個URL以獲得真正的JSON響應並設置auto和handleAs屬性。 我還添加了一個帶有偵聽器的小腳本,用於響應事件。 偵聽器工作正常並處理響應,但dom-repeat模板中的跨距不會呈現。
我正在使用Polymer 1.0.2和鐵元素1.0.0
您似乎缺少文檔-
示例的lastresponse
屬性中的字符。
您必須將lastResponse
更改為last-response
。 從iron-ajax github頁面看這個例子。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.