聚合物iron-ajax数据绑定示例不起作用

Ema*_*ger 2 ajax polymer

我在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

Mat*_*olo 10

看来文档中缺少示例属性中的-字符lastresponse.

你必须lastResponse改为last-response.从iron-ajax github页面看这个例子.

  • 文档没有遗漏任何内容.lastResponse是自定义元素<iron-ajax>的属性.将属性转换为属性时,必须将camelCase转换为带连字符的属性.因此,lastResponse在用作属性时成为最后响应. (3认同)