Polymer iron-ajax 数据绑定示例不起作用
Polymer iron-ajax data binding example not working
我在使用 iron-ajax 和 Polymer 1.0.2 中的数据绑定时遇到问题。即使稍作改动 example from the Polymer documentation 也不起作用。
这是我修改后的代码:
<!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 模板中的跨度。
我正在使用聚合物 1.0.2 和铁元素 1.0.0
您的文档似乎在示例的 lastresponse
属性中缺少 -
字符。
您必须将 lastResponse
更改为 last-response
。
查看 iron-ajax github 页面中的 this 示例。
在元素上使用属性时,必须将驼峰句转换为破折号句,我的意思是:
lastResponse 映射到 last-response
我在使用 iron-ajax 和 Polymer 1.0.2 中的数据绑定时遇到问题。即使稍作改动 example from the Polymer documentation 也不起作用。
这是我修改后的代码:
<!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 模板中的跨度。
我正在使用聚合物 1.0.2 和铁元素 1.0.0
您的文档似乎在示例的 lastresponse
属性中缺少 -
字符。
您必须将 lastResponse
更改为 last-response
。
查看 iron-ajax github 页面中的 this 示例。
在元素上使用属性时,必须将驼峰句转换为破折号句,我的意思是:
lastResponse 映射到 last-response