![](/img/trans.png)
[英]Backbone-relational: Association key won't work unless it's the same as the foreign key
[英]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
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
backbone.js
,第1019行Uncaught TypeError: undefined is not a function
。
如果我省略“關系”填充程序,我會得到Uncaught TypeError: Cannot set property 'Relational' of undefined
在backbone-relational.js
Uncaught TypeError: Cannot set property 'Relational' of undefined
。 它所談論的“未定義”是Backbone
。 因此,如果我省略“關系”填充程序, backbone-relational.js
仍然會被加載,但它不知道Backbone。
我該如何解決?
事實證明我需要jQuery。
shim:
"underscore":
exports: "_"
"backbone":
deps: ["underscore", "jquery"]
exports: "Backbone"
"relational":
deps: ["backbone"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.