嗨,我是主干新手,我有一个页面,我想在其中显示有关模型的信息。当我尝试在控制台上访问它时效果很好
前任:
collection = new Poster.Colections.Posts()
collection.fetch({reset: true})
post = collection.get(1)
以上工作正常
现在,当我尝试在routers
页面上的函数中执行此操作时,它返回 undefined
post_router.js
class Poster.Routers.Posts extends Backbone.Router
routes:
'posts':'index'
'':'index'
'posts/new': 'new'
'posts/:id': 'show'
initialize: ->
@collection = new Poster.Collections.Posts()
@collection.fetch({reset: true})
index: ->
view = new Poster.Views.PostsIndex(collection: @collection)
$('#index_container').html(view.render().el)
show: (id) ->
post = @collection.get(id)
view = new Poster.Views.PostsShow(model: post)
$('#index_container').html(view.render().el)
new: ->
view = new Poster.Views.PostsNew(collection: @collection)
$('#index_container').html(view.render().el)
我对javascript和骨干真的很陌生,我迷路了。有人可以帮忙吗