我正在使用Ruby on Rails API服務器學習Ember.js。我已經獲得了所有設置和工作的路線,模板和模型 - 但是一旦數據從API服務器加載,模板就不會重新渲染。我沒有收到任何錯誤消息,並且我知道客戶正在看着Ember檢查員加載。Ember.js在模型加載後不能重新呈現模板
客戶名單應該顯示正在從API服務器裝入正確start
客戶名單後:
路由器
// javacripts/router.js
App.Router.map(function() {
this.resource('customers', { path: "/" });
});
客戶路線
// javascripts/routes/customer_routes.js
App.CustomersRoute = Ember.Route.extend({
model: function() {
return this.store.find('customer');
},
renderTemplate: function() {
this.render('customers/index');
}
});
客戶模式
// javascripts/models/customer.js
App.Customer = DS.Model.extend({
name: DS.attr('string')
});
客戶索引模板
// javacripts/templates/customers/index.js.handlebars
<ul>
<li>start</li>
{{#each customers}}
<li>{{name}}</li>
{{/each}}
</ul>
商店
// javacripts/store.js
App.ApplicationAdapter = DS.ActiveModelAdapter.extend({
namespace: 'api/v1'
});
是否有任何實際加載,如你的應用程序模板文件? – Ryan
@ryan - 它看起來像一切正在加載就好。 「application.js.handlebars」和「index.js.handlebars」都正在呈現。但索引中的{{#each}}'循環總是空的 – lightswitch05
我想知道是因爲你使用的擴展是奇怪的。通常文件只是用'.handlebars'或'.hbs'擴展,我從來沒有見過'.js.handlebars'。 – Ryan