更新:
我有一个简单的骨干关系模型:
@App.M.Product = Backbone.RelationalModel.extend
defaults: {}
url: App.D.dataURL
relations: [
{
type: Backbone.HasMany
key: 'templates'
relatedModel: 'App.M.Template'
collectionType: 'App.C.Templates'
reverseRelation:
key: 'product'
}
{
type: Backbone.HasMany
key: 'pages'
relatedModel: 'App.M.Page'
collectionType: 'App.C.Pages'
reverseRelation:
key: 'product'
}
{
type: Backbone.HasMany
key: 'uploaded_images'
relatedModel: 'App.M.UploadedImage'
collectionType: 'App.C.UploadedImages'
reverseRelation:
key: 'product'
}
]
initialize: ->
if @get('minimumNumberOfPages') < 1
@set 'minimumNumberOfPages', 1
fixPages: ->
col = @get 'pages'
col.each (page) ->
page.collection = col
还有一个更简单的测试套件:
"use strict"
describe 'Product', ->
pr = null
beforeEach ->
pr = new App.M.Product
it 'should be defined', ->
expect(pr).toBeDefined()
但是,模型无法初始化(取自 testem 的终端输出):
TypeError: Cannot read property 'prototype' of undefined
at Backbone.HasMany.Backbone.Relation.extend.initialize (http://localhost:7357/app/bower_components/backbone-relational/backbone-relational.js:835:78)
at Backbone.Relation (http://localhost:7357/app/bower_components/backbone-relational/backbone-relational.js:537:9)
at new child (http://localhost:7357/app/bower_components/backbone/backbone-min.js:1:25220)
at _.extend.initializeRelation (http://localhost:7357/app/bower_components/backbone-relational/backbone-relational.js:137:5)
at null.<anonymous> (http://localhost:7357/app/bower_components/backbone-relational/backbone-relational.js:1176:31)
at Array.forEach (native)
at Function.w.each.w.forEach (http://localhost:7357/app/bower_components/underscore/underscore-min.js:1:599)
at Backbone.RelationalModel.Backbone.Model.extend.initializeRelations (http://localhost:7357/app/bower_components/backbone-relational/backbone-relational.js:1175:6)
at Backbone.RelationalModel.Backbone.Model.extend.set (http://localhost:7357/app/bower_components/backbone-relational/backbone-relational.js:1373:11)
at Backbone.Model (http://localhost:7357/app/bower_components/backbone/backbone-min.js:1:3929)
这是为什么?该应用程序工作正常,测试不正常。