我有添加第二个收藏到我的骨干/ 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