我有添加第二個收藏到我的骨幹/ Rails項目骨幹和Rails的
這裏的一個問題是收集公司
class Raffler.Collections.Companies extends Backbone.Collection
url: '/api/companies'
model: Raffler.Models.Company
這裏我的類文件是爲Model
類文件class Raffler.Models.Company extends Backbone.Model
繼承人路由器
這裏是視圖
class Raffler.Views.CompaniesIndex extends Backbone.View
template: JST['companies/index']
initialize: ->
@companies.on('reset', @render, this)
render: ->
$(@el).html(@template(companies: @companies))
this
,當我到達@companies.on
它倒下 - 錯誤是「對」無法調用未定義。
我不明白這個錯誤 - 我已將@companies
設置爲路由器中的集合,並將它傳遞到在路由器類中創建的視圖中。
我在應用程序中的另一個集合上實現了完全相同的代碼,所以我想知道是否因爲我試圖添加第二個集合?
這一切都完美的作品JavaScript控制檯內的瀏覽器,當我做了以下
companies = new Raffler.Collection.Companies()
companies.fetch()
companies.length
我可以看到它正在調用服務器並返回正確的記錄數 - 那麼,爲什麼沒有按應用程序中的代碼工作?有任何想法嗎?
Thankyou Thankyou ...這工作。謝謝。 – 2012-04-23 19:27:30