0

我在CoffeeScript中以下骨幹路由​​器定義:無法獲取骨幹關係與AMD(RequireJS)工作

// 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 functionbackbone.js,線路1019

如果我省略了「關係」墊片,我代替backbone-relational.js得到Uncaught TypeError: Cannot set property 'Relational' of undefined。它所說的「未定義」是Backbone。所以如果我省略了「關係」墊片,backbone-relational.js仍然被加載,但它不知道Backbone。

我該如何解決這個問題?

回答

0

原來我需要jQuery。

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

我討厭當用戶忽略給他們答案的人,然後添加並接受他們自己的答案。 – Tim 2014-02-19 13:58:03