无法获得Backbone-relational使用AMD(RequireJS) [英] Can't get Backbone-relational to work with AMD (RequireJS)
问题描述
我在CoffeeScript中有以下的Backbone路由器定义:
// appointments_router.js.coffee
define [ app,appointment],(App) - >
class Snip.Routers.AppointmentsRouter extends Backbone.Router
initialize:(options) - >
@appointments = new Snip.Collections.AppointmentsCollection()
@ appointments.reset options.appointments
这是依赖于它的约会模块:
// appointment.js.coffee
pre>
define [app,relational],(App) - >
class Snip.Models.Appointment extends Backbone.RelationalModel
paramRoot:appointment
defaults:
time_block_type_code:APPOINTMENT
start_time:null
start_time_time:null
start_time_ymd:null
stylist:{}
客户端:{}
注释:''
最后,这里是我的
application.js.coffee
:require
路径:
下划线:lodash.min
约会:backbone / models / appointment
约定路由器:骨干/路由器/约会_路由器
关系:骨干关系
shim:
underscore:
exports: :
deps:[underscore]
exports:Backbone
relational:
deps:[backbone]
requirejs [ appointmentsRouter],(AppointmentsRouter) - >
window.router = new Snip.Routers.AppointmentsRouter({appointments:[]})
Backbone.history.start()
当我加载页面时,我得到
Uncaught TypeError:undefined不是
骨干上的一个函数
。
如果我省略关系垫片,我会得到
Uncaught TypeError:Can not set在
的属性关系。它所说的未定义是backbone-relational.js
中未定义Backbone
。所以如果我省略关系垫片,backbone-relational.js
仍然被加载,但它不知道Backbone。
如何解决这个问题?
解决方案结果我需要jQuery。
shim:
underscore:
exports:_
backbone:
deps:[underscore,jquery]
exports:Backbone
relational:
deps:[backbone]
I have the following Backbone router definition in CoffeeScript:
// appointments_router.js.coffee define ["app", "appointment"], (App) -> class Snip.Routers.AppointmentsRouter extends Backbone.Router initialize: (options) -> @appointments = new Snip.Collections.AppointmentsCollection() @appointments.reset options.appointments
Here is the "appointment" module on which it depends:
// appointment.js.coffee define ["app", "relational"], (App) -> class Snip.Models.Appointment extends Backbone.RelationalModel paramRoot: "appointment" defaults: time_block_type_code: "APPOINTMENT" start_time: null start_time_time: null start_time_ymd: null stylist: {} client: {} notes: ''
And finally, here is my
application.js.coffee
:require paths: underscore: "lodash.min" appointment: "backbone/models/appointment" appointmentsRouter: "backbone/routers/appointments_router" relational: "backbone-relational" shim: "underscore": exports: "_" "backbone": deps: ["underscore"] exports: "Backbone" "relational": deps: ["backbone"] requirejs ["appointmentsRouter"], (AppointmentsRouter) -> window.router = new Snip.Routers.AppointmentsRouter({appointments: []}) Backbone.history.start()
When I load the page, I get
Uncaught TypeError: undefined is not a function
onbackbone.js
, line 1019.If I omit the "relational" shim, I instead get
Uncaught TypeError: Cannot set property 'Relational' of undefined
inbackbone-relational.js
. The "undefined" it's talking about isBackbone
. So if I omit the "relational" shim,backbone-relational.js
still gets loaded, but it doesn't know about Backbone.How do I fix this?
解决方案Turns out I need to require jQuery.
shim: "underscore": exports: "_" "backbone": deps: ["underscore", "jquery"] exports: "Backbone" "relational": deps: ["backbone"]
这篇关于无法获得Backbone-relational使用AMD(RequireJS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!