gpt4 book ai didi

object - 主干和 Requirejs。如何从任何地方访问我的 Backbone 路由器

转载 作者:行者123 更新时间:2023-12-01 08:07:15 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com