EmberJS는 Routes를 사용하여 모델, 뷰 및 컨트롤러를 연결하는 것을 권장하며 페이지의 기본 콘텐츠를 설정하는 데 매우 편리합니다. 그러나 두 번째 소스의 정보를 표시하는 사이드 바가 있다고 가정합니다. 예 : RSS 피드. 또는 일부 서버 통계에 연결된 상태 패널 별도의 모델에 연결하는 모든 템플릿 {{View MessageView}}에 추가 할 수있는보기가 필요합니다.경로가없는 경우보기, 컨트롤러 및 모델을 연결하는 올바른 관용구는 무엇입니까?
이것을 수행하는 '엠버 웨이'는 무엇입니까?
지금까지 내가 할 수있는 최선의 방법은 명시 적 View 및 Controller 객체를 초기화 함수로 재정 의하여 연결하는 것입니다. 예를 들어 :
/*
* 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'),
},
];
그러나 정말 필요한 것은 경로 기능이 이미 무엇을 재현 할 수있는 방법입니다.
더 좋은 방법이 있습니까?
여러 개의 독립된보기 영역이있는 대시 보드 스타일 페이지의 예가 있습니까?
감사합니다 앤드류