【问题标题】:Polymer - iron-ajax - google sheets JSON data bindingPolymer - Iron-ajax - 谷歌表格 JSON 数据绑定
【发布时间】:2016-11-03 03:43:25
【问题描述】:

聚合物新手在这里..

尝试通过获取其 JSON 数据,为 Google 表格文档中的数据设置一些 HTML 的转发器。

https://spreadsheets.google.com/feeds/list/1jJxd4Q3MzZLxMZ4pO9E56UL4eZInuPNwUdrFXk9qds8/od6/public/values?alt=json

我正在尝试使用:

// Load the JSON file from Google
<iron-ajax auto url="https://spreadsheets.google.com/feeds/list/1jJxd4Q3MzZLxMZ4pO9E56UL4eZInuPNwUdrFXk9qds8/od6/public/values?alt=json"
               handle-as="json"
               last-response="{{data}}"></iron-ajax>

//Create the HTML repeater to list the image items
    <template is="dom-repeat" items="{{data}}">
      <a href="{{feed.entry.item.gsx$imageurl.$t}}"><img src="{{feed.entry.item.gsx$imagethumburl.$t}}" data-big="{{feed.entry.item.gsx$imageurl.$t}}" data-title="{{feed.entry.item.gsx$imagetitle.$t}}" data-description="{{feed.entry.item.gsx$imagecaption.$t}}" ></a>
    </template>

但是,我似乎无法在 JSON 提要中定位>entry>行号

我的控制台一直在说:

polymer-micro.html:277 [dom-repeat::dom-repeat]:items 的预期数组,找到对象 {版本:“1.0”,编码:“UTF-8”,提要:对象}

任何帮助将不胜感激!

【问题讨论】:

    标签: json google-sheets polymer


    【解决方案1】:

    您的代码中有一些错误。

    首先,一旦您进入dom-repeat,您必须将当前项目简称为item。如果需要,您可以通过将as 属性应用于dom-repeat 元素来更改变量名称。

    其次,当使用dom-repeat 时,items 属性必须是一个实际的数组。在您的情况下,您使用的是整个 JSON 响应。你应该把它改成items="{{data.feed.entry}}"

    这就是说,最终的代码应该是这样的:

    // Load the JSON file from Google
    <iron-ajax auto url="https://spreadsheets.google.com/feeds/list/1jJxd4Q3MzZLxMZ4pO9E56UL4eZInuPNwUdrFXk9qds8/od6/public/values?alt=json"
                   handle-as="json"
                   last-response="{{data}}"></iron-ajax>
    
    //Create the HTML repeater to list the image items
    <template is="dom-repeat" items="{{data.feed.entry}}">
      <a href="{{item.gsx$imageurl.$t}}"><img src="{{item.gsx$imagethumburl.$t}}" data-big="{{item.gsx$imageurl.$t}}" data-title="{{item.gsx$imagetitle.$t}}" data-description="{{item.gsx$imagecaption.$t}}" ></a>
    </template>
    

    【讨论】:

    • 谢谢亚历克斯。聚合物一直是一个陡峭的学习曲线。真的很感激。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多