【发布时间】:2013-12-29 06:14:46
【问题描述】:
js 文件:
class BackApp.Collections.Posts extends Backbone.Collection
url: '/api/posts'
model: BackApp.Models.Post
class BackApp.Models.Post extends Backbone.Model
class BackApp.Routers.Posts extends Backbone.Router
routes:
'': 'index'
initialize: ->
@collection = new BackApp.Collections.Posts
@collection.fetch()
index: ->
#view = new BackApp.Views.PostsIndex(collection: @collection)
#$("#container").html(view.render().el)
铁路路线:
scope "api" do
resources :posts
end
root :to => 'main#index'
所以,当我尝试在 chrome 控制台中获取集合时:
collection = new BackApp.Collections.Posts
collection.fetch()
collection.length # => 3
但是如果我在初始化函数的帖子路由文件中写它(console.log)它显示 0 为什么?
【问题讨论】:
-
别忘了我。 :)
标签: ruby ruby-on-rails-3 backbone.js coffeescript