Using Polymer iron-ajax in repeating template

元气小坏坏 提交于 2019-12-05 19:50:28

Firstly as vasek says, your JSON is incorrect. dom-repeat needs an array to iterate over and your JSON is currently returning an object. Secondly, you are accessing the properties on the iron-ajax element incorrectly. As the docs state

In order to configure camel-case properties of elements using attributes, dash- case should be used in the attribute name.

You are trying to set handleAs and lastResponse. In order to do these you need to change them to the dash-case:

<iron-ajax auto url="names.json" handle-as="json" last-response="{{data}}"></iron-ajax>

Otherwise, everything else should work correctly.

Your json file is in wrong format. It should be like this:

    [
        {
            "firstName": "John",
            "lastName": "Smith"
        },
        {
            "firstName": "Jane",
            "lastName": "Doe"
        }
    ]

I was also stuck with a similar code, unfortunately the above answers didn't solve the issue for me. However, when I put the <iron-ajax> element after the <template is="dom-repeat">, it worked for me.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!