无法获得Backbone-relational使用AMD(RequireJS) [英] Can't get Backbone-relational to work with AMD (RequireJS)

查看:279
本文介绍了无法获得Backbone-relational使用AMD(RequireJS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CoffeeScript中有以下的Backbone路由器定义:

  // appointments_router.js.coffee 
define [ app,appointment],(App) - >
class Snip.Routers.AppointmentsRou​​ter 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:{}
客户端:{}
注释:''
pre>

最后,这里是我的 application.js.coffee

  require 
路径:
下划线:lodash.min
约会:backbone / models / appointment
约定路由器:骨干/路由器/约会_路由器
关系:骨干关系
shim:
underscore:
exports: :
deps:[underscore]
exports:Backbone
relational:
deps:[backbone]

requirejs [ appointmentsRou​​ter],(AppointmentsRou​​ter) - >
window.router = new Snip.Routers.AppointmentsRou​​ter({appointments:[]})
Backbone.history.start()

当我加载页面时,我得到 Uncaught TypeError:undefined不是骨干上的一个函数



如果我省略关系垫片,我会得到 Uncaught TypeError:Can not set在 backbone-relational.js 中未定义的属性关系。它所说的未定义是 Backbone 。所以如果我省略关系垫片, backbone-relational.js 仍然被加载,但它不知道Backbone。



如何解决这个问题?

解决方案

结果我需要jQuery。

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


I have the following Backbone router definition in CoffeeScript:

// 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

Here is the "appointment" module on which it depends:

// 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: ''

And finally, here is my 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()

When I load the page, I get Uncaught TypeError: undefined is not a function on backbone.js, line 1019.

If I omit the "relational" shim, I instead get Uncaught TypeError: Cannot set property 'Relational' of undefined in backbone-relational.js. The "undefined" it's talking about is Backbone. So if I omit the "relational" shim, backbone-relational.js still gets loaded, but it doesn't know about Backbone.

How do I fix this?

解决方案

Turns out I need to require jQuery.

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

这篇关于无法获得Backbone-relational使用AMD(RequireJS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆