我在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
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: ''
最后,这是我的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()
当我加载页面时,我会在Uncaught TypeError: undefined is not a function
第1019行获得backbone.js
。
如果我省略“关系”垫片,我会在Uncaught TypeError: Cannot set property 'Relational' of undefined
中获得backbone-relational.js
。它所谈论的“未定义”是Backbone
。因此,如果我省略“关系”垫片,backbone-relational.js
仍会被加载,但它不知道Backbone。
我该如何解决这个问题?
答案 0 :(得分:2)
你可以使用一个垫片配置,需要.. drop amd,backbone did ..
看一看 https://github.com/DarrenHurst/BroadStreet
有关如何配置填充程序。
答案 1 :(得分:0)
原来我需要jQuery。
shim:
"underscore":
exports: "_"
"backbone":
deps: ["underscore", "jquery"]
exports: "Backbone"
"relational":
deps: ["backbone"]