Javascript Can';t获得与AMD(RequireJS)合作的主干关系
我在CoffeeScript中有以下主干路由器定义:Javascript Can';t获得与AMD(RequireJS)合作的主干关系,javascript,backbone.js,coffeescript,requirejs,backbone-relational,Javascript,Backbone.js,Coffeescript,Requirejs,Backbone Relational,我在CoffeeScript中有以下主干路由器定义: // appointments_router.js.coffee define ["app", "appointment"], (App) -> class Snip.Routers.AppointmentsRouter extends Backbone.Router initialize: (options) -> @appointments = new Snip.Collections.Appointm
// 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
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: ''
最后,这里是我的应用程序.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()
当我加载页面时,我在backbone.js
第1019行得到uncaughttypeerror:undefined不是一个函数
如果省略“relational”垫片,则会得到uncaughttypeerror:无法在backbone relational.js
中设置未定义的属性“relational”。它所说的“未定义”是主干网
。因此,如果省略“relational”垫片,backbone relational.js
仍然会被加载,但它不知道主干
我该如何解决这个问题?事实证明我需要jQuery
shim:
"underscore":
exports: "_"
"backbone":
deps: ["underscore", "jquery"]
exports: "Backbone"
"relational":
deps: ["backbone"]
您可以根据需要使用垫片配置。。放弃amd,主干网做到了
看看
了解如何配置垫片。我讨厌用户忽略给出答案的人,然后添加并接受自己的答案。