Iron-ajax Data binding

北城余情 提交于 2019-12-05 12:56:22

The property params is of type Object. Unlike in the linked example, you can just return a native object.

processParams: function(part1, qry, maxResults1, key1) {
    return {
        part: part1,
        q: qry,
        maxResults: maxResults1,
        key:key1
    };
}
 <template is="dom-bind" id="app">
  <iron-ajax auto
      url="https://www.googleapis.com/youtube/v3/search"
      params='{"part":"snippet", "q":"polymer", "key": "AIzaSyAuecFZ9xJXbGDkQYWBmYrtzOGJD-iDIgI", "type": "video"}'
      handle-as="json"
      last-response="{{ajaxResponse}}"></iron-ajax>

    <template is="dom-repeat" items="[[ajaxResponse.items]]">
      <div class="horizontal-section">
        <h2><a href="[[url(item.id.videoId)]]" target="_blank">[[item.snippet.title]]</a></h2>
        <iron-image src="[[item.snippet.thumbnails.high.url]]" width="256" height="256" sizing="cover" preload fade></iron-image>
        <p>[[item.snippet.description]]</p>
      </div>
    </template>
<script>
var app = document.querySelector('#app');

app.url = function (videoId) {
  return 'https://www.youtube.com/watch?v=' + videoId;
};
</script>

I'm sorry. the ajax query returns a json array of Youtube videos with the paramaters listed in the property "params". the one way binding "[[ajaxResponse.items]]" binds the response to the repeating template "dom-repeat". the url function just appends the videoId to the individual links. I copied the code straight from the iron-ajax demo that ships with polymer starter kit

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