我知道EmberJS建議使用路線將模型,視圖和控制器連接在一起,這對於設置頁面的主要內容非常方便。不過,假設我有一個側邊欄來顯示第二個來源的信息。例如rss提要。或連接到某些服務器狀態的狀態面板, 我想要一個可添加到連接到單獨模型的任何模板{{view MessageView}}的視圖。當沒有路線存在時,鏈接視圖,控制器和模型的正確方式是什麼?
什麼是'燼途'來做到這一點。
到目前爲止,我能做的最好的事情是讓顯式的View和Controller對象覆蓋init函數以將它們連接在一起。 例如:
/*
* The messages class is a free floating list of messages that can be plugged into any page.
* it is implemented as a view with a separate controller and model.
* As its not associated with a route we need to bind the view, controller and model together directly using
* init statements.
*/
/**************************
* Model
**************************/
App.Message = DS.Model.extend({
msg: DS.attr('string'),
author: DS.attr('string'),
date: DS.attr('date'),
display_class: DS.attr('string')
});
/**************************
* Route
**************************/
//App.MessageRoute = Ember.Route.extend({
// model : function() {
// return this.get('store').findAll('message');
// }
//});
/**************************
* Views
**************************/
App.MessageView = Em.View.extend({
init: function() {
// this._super();
this.set("controller", App.MessageController.create());
},
});
/**************************
* Controllers
**************************/
App.MessageController = Em.ArrayController.extend({
init: function() {
// this._super();
this.set("model", model : function() {
return this.get('store').findAll('message');
});
},
});
/**************************
* Fixture
**************************/
App.Message.FIXTURES = [{
id: 1,
msg: "App website will be down for maintenance for 4 hours on Friday 29th Nov",
author: { name: "Admin" },
date: new Date('2013-11-18T19:00:00Z'),
display_class: 'warning'
}, {
id: 2,
msg: "Tropical Cyclone may affect North Island net week [read more](http://www.bom.gov.au/cyclone/)",
author: { name: "WeatherMan" },
date: new Date('2013-11-18'),
},
];
但是我真正需要的是一些方式重現什麼路由功能已經這樣做。
有沒有更好的方法?
是否有一個具有多個獨立視圖區域的儀表盤樣式頁面的示例?
由於安德魯