我正在使用requirejs工作在我的第一個項目上。我有一個路由器和一個視圖,我想在單擊一個項目時從視圖中訪問我的Router.navigate()方法。我使用CoffeeScript。我怎樣才能讓路由器全球?骨幹和Requirejs。如何從任何地方訪問我的中樞路由器
router.coffee:
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')
view.coffee
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()
爲什麼不就叫'Backbone.history.navigate()'? – loganfsmyth 2013-05-06 15:21:34
@loganfsmyth oooh,抱歉,您忘記以答案的形式發佈您的問題。 :) – Kato 2013-05-06 15:25:13