簡體   English   中英

無法使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
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 undefinedbackbone-relational.js Uncaught TypeError: Cannot set property 'Relational' of undefined 它所談論的“未定義”是Backbone 因此,如果我省略“關系”填充程序, backbone-relational.js仍然會被加載,但它不知道Backbone。

我該如何解決?

你可以使用一個墊片配置與Require .. drop amd,backbone do ..

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

如何配置墊片。

事實證明我需要jQuery。

  shim:
    "underscore":
      exports: "_"
    "backbone":
      deps: ["underscore", "jquery"]
      exports: "Backbone"
    "relational":
      deps: ["backbone"]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM