0
Backbone + requirejs를 사용하여 응용 프로그램을 구성합니다. 아래 모듈에서 초기화 기능을 사용하여이 모듈에서 "HomeView, InnerView"라는 다른 두 모듈의 초기화 함수를로드합니다. Backbone.history 이벤트를 수신하는 것을 좋아합니다. 모듈은 그런 사건을 듣지 않았다. 다른보기 내부 backbone.history의 이벤트를 수신에서 저를 방지하는 잘못 무엇Backbone은 Backbone.history 이벤트를 수신합니다.
라우터
// Filename: router.js
define([
'jquery',
'underscore',
'backbone',
'app/config',
'app/views/homeview',
'app/views/inner_view'
], function($, _, Backbone, Config, HomeView, InnerView) {
var AppRouter = Backbone.Router.extend({
initialize: function() {
},
routes: {
// Define some URL routes
'': 'defaultRoute',
'!/home': 'defaultRoute',
'!/activities': 'activities',
'!/activities/:id': 'activity',
'!/vacancies': 'vacancies',
'!/vacancies/:id': 'vacancies',
// 404, not found
'*actions': '404'
},
defaultRoute: function() {
//if this route is served from inner pages, we have to trigger "close:Inner"
Backbone.trigger('close:Inner');
Backbone.current = 'Home';
},
activities: function(){
Backbone.trigger('view:Activities');
Backbone.trigger('close:'+Backbone.current);
Backbone.current = 'Activities';
},
activity: function(id){
Backbone.trigger('close:' + Backbone.current);
Backbone.current = 'Activity';
},
vacancies: function(){
},
404: function(actions) {
// We have no matching route, lets display 404
$('.content_wapper').html(actions + " no such page on the system");
}
});
var initialize = function() {
HomeView.initialize();
InnerView.initialize();
Backbone.appRouter = new AppRouter();
Backbone.history.start();
};
return {
initialize: initialize
};
});
?
Innerview 모듈
// Filename: views/boilerplate.js
define([
'jquery',
'underscore',
'backbone',
'app/config',
'text!templates/inner_header.html',
'bootbox',
'text!templates/breadcrumb.html',
'purl'
], function($, _, Backbone, Config, inner_header_template, bootbox, breadcrumbTemplate) {
var url = $.url(),
InnerView = Backbone.View.extend({
el: $(".header_content"),
template: _.template(inner_header_template),
initialize: function(options) {
Backbone.history.on('route:activities', this.activities);
},
render: function() {},
activities: function() {
alert('activities');
},
events: {},
close: function() {
$('.top_menu').remove();
$('.main_menu_inner').remove();
$('.content_container').empty();
$(this.el).unbind();
delete this.$el; //delete the jQuery wrapped object variable
delete this.el; //delete the variable reference to this node
}
});
var initialize = function() {
new InnerView();
};
return {
initialize: initialize
};
});
'Backbone.history.on ('route : activities ', this.activities); 그리고 내가 언급 한 이벤트는 나를 위해 완벽하게 작동한다 : – ahmedsaber111
어디에서'route : activities'를 실행 시켰습니까? 사건? –
라우터 모듈의 초기화 기능으로 초기화 된 InnerView 내부 – ahmedsaber111