gpt4 book ai didi

javascript - 无法让 Backbone 关系与 AMD 一起使用 (RequireJS)

转载 作者:行者123 更新时间:2023-12-02 19:26:51 27 4
gpt4 key购买 nike

我在 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()

当我加载页面时,我在 backbone.js 第 1019 行收到 Uncaught TypeError: undefined is not a function

如果我省略“关系”填充程序,则会在 backbone-relational.js 中收到 Uncaught TypeError: Cannot set property 'Relational' of undefined 。它所说的“未定义”是Backbone。因此,如果我省略“关系”填充程序,backbone-relational.js 仍然会加载,但它不知道 Backbone。

如何解决这个问题?

最佳答案

您可以使用带有 Require.. drop amd 的 shim 配置,backbone did..

看看 https://github.com/DarrenHurst/BroadStreet

了解如何配置垫片。

关于javascript - 无法让 Backbone 关系与 AMD 一起使用 (RequireJS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11955309/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com