1
js文件:骨幹取收集+ Rails的
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'
所以,當我試圖像鉻控制檯抓取集合:
collection = new BackApp.Collections.Posts
collection.fetch()
collection.length # => 3
但如果我寫它(console.log)在初始化函數中的帖子路徑文件它顯示0 爲什麼?
別忘了我。 :) – SergeyKutsko