Ember setupController请求

时间:2016-06-12 18:06:17

标签: ember.js ember-data ember-router

import Ember from 'ember';

export default Ember.Route.extend({
  model: function(){
    return this.store.findAll('podcast')
  },
  setupController(controller, model){
    model.forEach(function(v){
      //i want to make a request here
    })
    controller.set('model', model)
  }
});

this.store.findAll('podcast')会返回播客Feed的网址。我想在setupController中提出请求,以便从网址获取/feed。它甚至可能吗?

1 个答案:

答案 0 :(得分:1)

当然只需使用本机jQuery AJAX调用。像这样:

<强>路线

import Ember from 'ember';

export default Ember.Route.extend({
    model: function(){
        return this.store.findAll('podcast')
    },

    setupController(controller, model) {
        controller.set('podcastFeeds', []);

        model.forEach( podcast => {
            Ember.$.ajax({
                url: podcast.get('feed'), // get the property
            }).then( feedData => {
                controller.get('podcastFeeds').addObject(feedData);
            }, () => {
                //handle error
            });
        });
    }
});

<强>模板

{{#each podcastFeeds as |podcastFeed|}}
    {{{podcastFeed}}}
{{/each}}