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
。它甚至可能吗?
答案 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}}