我正在使用 requirejs 处理我的第一个项目。我有一个路由器和一个 View ,我想在单击项目时从 View 访问我的 Router.navigate() 方法。我使用 CoffeeScript。如何使路由器全局化?
路由器.咖啡:
define [
'jquery'
'backbone'
'application/views/mainView'
'application/models/app'
],($,Backbone,MainView,App)->
class Router extends Backbone.Router
routes:
'organisation': 'organisationScreen'
'*actions': 'organisationScreen'
constructor:() ->
super @routes
initialize:()->
Backbone.history.start() #pushState: true
console.log " The Route Initialized"
organisationScreen:()->
$('.slides').fadeOut()
$('.confBlock').removeClass('onshow')
$('.organisationsBlock').addClass('onshow')
查看咖啡
define [
'jquery'
'backbone'
'application/views/conferenceView'
],($,Backbone,ConferenceView)->
class OrganisationView extends Backbone.View
#el: '#appcontainer'
tagName : 'li'
className : 'organisation'
events:
'click .org-item' : 'choice'
template : _.template($('#Organisation-template').html())
initialize : ()->
...
render: ()->
...
choice:(ev)->
# Call Router.navigate()
最佳答案
全部 Router::navigate
是打电话Backbone.history.navigate
所以我就用那个。 Here is the source
choice: (ev)->
Backbone.history.navigate(...);
关于object - 主干和 Requirejs。如何从任何地方访问我的 Backbone 路由器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16399802/