我在使用主干 js 时遇到了一些困难。目前,我有一个通过 json 向骨干网提供信息的 rails 应用程序。看来这一切正常,因为当我导航到 URL 时,会显示 json 数据。我在使用 fetch 方法时遇到了困难。下面是我的代码:
jQuery ->
class Event extends Backbone.Model
url: '/events/get_last'
defaults:
name: 'This isnt from the server'
date_of: '2012-03-01'
max_attendees: '300'
class EventList extends Backbone.Collection
url: '/events/get_events'
model: Event
class EventView extends Backbone.View
el: $ 'body'
model: Event
initialize: (options) ->
_.bindAll @
@event = new Event
@event.fetch()
@render()
render: ->
$(@el).append "<span>#{@event.get 'name'}"
class EventRouter extends Backbone.Router
routes :
'' : 'home'
'dashboard' : 'render_data_view'
'default' : 'default_view'
home: ->
console.log "home"
render_data_view: ->
event_view = new EventView
default_view: ->
console.log 'the default view was hit'
initialize: ->
Backbone.history.start(pushState: true)
event_router = new EventRouter