我讀過這個,它似乎是我正在尋找的答案,但似乎並不完全理解發生了什麼。 Dynamically choosing a view at runtime with Ember + Handlebars。如何在視圖內切換視圖?
FWIW,ember.StateManager據我瞭解不能嵌套工作。因此,如果應用程序視圖中包含子部分,則無法將其用於單個頁面應用程序,以便在應用程序視圖和用戶配置文件視圖之間切換。所以我覺得必須有另一種方式。
所以簡單的example來說明我正在嘗試做什麼。
(function($){
window.APP = Ember.Application.create();
/*models*/
$.models = {};
$.models.c = Ember.Object.create({
first_name: "joe",
last_name: "blow"
});
$.models.a = Ember.Object.create({
street:"1 wall street plaza",
city: "New York City",
state: "NY",
zip: "10101"
});
//views (sections of the application
$.views = {};
$.views.name = Ember.View.extend({template:Ember.Handlebars.compile("{{content.first_name}} {{content.last_name}}"),
contentBinding: "$.models.c"
});
$.views.address = Ember.View.extend({template: Ember.Handlebars.compile("{{content.street}} {{content.city}} {{content.state}} {{content.zip}}"),
contentBinding: "$.models.a"});
//something to hold the current view(section)
$.navmodel = Ember.Object.create({current:$.views.address});
//view to display the current view(section)
$.nav = Ember.View.create({template: Ember.Handlebars.compile("{{view current}}"),
currentBinding: "$.navmodel.current"
});
//add to page
$.nav.appendTo("#content");
//switch between the pages
setTimeout(function(){
$.navmodel.set("current", $.views.name);
alert("set");
},1000);
})(jQuery);
是的,我知道Ember.StateManager可用於這一點,但如果我再需要嵌套子視圖的StateManager不會將它的工作?
Ember.StateManager不再是核心的一部分。 – 2014-02-19 18:05:22