I'm struggling with my Backbone router and module definitions in CoffeeScript. Can someone help me troubleshoot?
// 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 code:
// 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: ''
Lastly, check out 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()
Encountering errors on page load such as
Uncaught TypeError: undefined is not a function
or Uncaught TypeError: Cannot set property 'Relational' of undefined
? Let's figure out how to resolve these issues.