我對Ember相當新,我開始編寫更復雜的應用程序。我一直在試圖弄清楚爲什麼爲索引定義控制器會破壞索引路徑的模型羣體。EmberJS:定義控制器斷開路由模式
我試過「setupcontroller」功能,但仍然沒有運氣。
,路線如下代碼:
App.IndexRoute = Ember.Route.extend({
model: function() {
return Ember.RSVP.hash({ //return promises for both models here
featuredJobs: $.getJSON('http://api.*********/featured/jobs', {'token': guestToken}),
featuredEmployers: $.getJSON('http://api.********/featured/employers', {'token': guestToken})
})
}
});
當我添加App.IndexController = Ember.Controller.extend({...
它打破了模型的{{#each}}幫手。 (不是應用程序)。我可以在Ember檢查器中看到分配給路線的模型。這裏是模板:
<div class="panel-body">
<div class="list-group ft-jobs">
{{#each featuredJobs}}
{{#linkTo 'job' _id class="list-group-item"}}
<h4 class="list-group-item-heading">{{title}}</h4>
<p class="list-group-item-text">{{description}}</p>
{{/linkTo}}
{{else}}
<p class="text-center">Sorry, no featured jobs are available.</p>
{{/each}} //END OF SNIPPET
我可能是錯的,但我認爲的IndexController需要是Ember.ArrayController,而不是僅僅Ember.Controller,因爲它的預期JSON對象的數組。 – rogMaHall
這是有道理的...謝謝,我明天會嘗試。 –
如果可以,請回報一下它是怎麼回事:)我對Ember也是相當新的,所以這只是我的第一本能,如果在添加控制器之前一切工作都正常。 – rogMaHall