2016-06-12 4 views
1
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')は、ポッドキャストフィードのURLを返します。 URLから/feedを取得するには、setupControllerにリクエストを送信します。それも可能ですか?Ember setupControllerリクエスト

答えて

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}} 
関連する問題