0
下面的代碼似乎並沒有工作:Ember視圖不顯示?
//The HTML
<div class="content">
<script type="text/x-handlebars" data-template-name="application">
<h1>Application</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="user-list">
<h2>Users</h2>
<ul>
{{#each App.userController}}
<li>{{name}}</li>
{{/each}}
</ul>
</script>
</div>
//The JS
var App = Ember.Application.create();
App.ApplicationController = Ember.Controller.extend();
App.ApplicationView = Ember.View.extend({
templateName: 'application'
});
App.User = Ember.Object.extend({
name: null,
xs:0,
turnover:0,
surveys:0
});
App.UsersView = Ember.View.extend({
templateName: 'user-list'
});
App.userController = Ember.ArrayController.create({
content: [],
init: function() {
var me = this;
$.getJSON('http://localhost:8000/', function(data) {
me.set('content', []);
$(data).each(function(index, value) {
var t = App.User.create({
name: value.name,
xs: value.xs,
turnover: value.turnover,
surveys: value.surveys
});
me.pushObject(t);
});
});
}
});
App.router = Ember.Router.create({
enableLogging: true,
root: Ember.Route.extend({
index: Ember.Route.extend({
route:'/',
connectOutlets:function(router) {
return router.get('applicationController').connectOutlet({
viewClass: App.UsersView,
controller: App.userController
});
}
}),
})
});
App.initialize(App.router);
userController
是正確地獲取數據。我認爲問題在於這個觀點。 <h2>Users</h2>
甚至沒有顯示在頁面上(雖然應用程序是)
你使用哪種版本的Ember? – mavilein 2013-03-11 10:14:32
哎呀,忘了包括:'v1.0.0-pre.4' – andy 2013-03-11 10:16:05
我想你已經從舊版本的Ember遷移這個代碼,現在它停止工作?這是因爲您在那裏使用舊的路由器API。新的路由器API不能以這種方式工作... – mavilein 2013-03-11 10:25:33