我有一个使用 Backbone.js 的应用程序。一切工作正常,但最近我将 RequireJS 添加到我的项目中,这当然让一切都崩溃了,所以我正在定义我的依赖项并使一切重新工作。
我得到的错误是Uncaught ReferenceError: JST is not defined.
我有以下 CoffeeScript 视图文件。注意 JST 行:
define ["app"], (App) ->
Snip.Views.Appointments ||= {}
class Snip.Views.Appointments.IndexView extends Backbone.View
template: JST["backbone/templates/appointments/index"]
initialize: () ->
@options.appointments.bind('reset', @addAll)
addAll: () =>
@options.appointments.each(@addOne)
addOne: (appointment) =>
view = new Snip.Views.Appointments.AppointmentView({model : appointment})
@$("ul").append(view.render().el)
我的“应用程序”依赖项本身具有 Backbone 和 Underscore 作为依赖项,所以我认为问题不在于 Backbone 不存在:
define ["underscore", "backbone"], (_, Backbone) ->
window.Snip =
Models: {}
Collections: {}
Routers: {}
Views: {}
当我加载页面时,我得到Uncaught ReferenceError: JST is not defined
.
我需要做什么才能让我的脚本了解 JST?
编辑:这是我的路径和东西
require
paths:
jquery: "jquery-1.7.2.min"
underscore: "lodash.min"
appointment: "backbone/models/appointment"
appointmentIndexView: "backbone/views/appointments/index_view"
appointmentsRouter: "backbone/routers/appointments_router"
relational: "backbone-relational"
shim:
"underscore":
exports: "_"
"backbone":
deps: ["underscore", "jquery"]
exports: "Backbone"
"relational":
deps: ["backbone"]
requirejs ["appointmentsRouter"], (AppointmentsRouter) ->
window.router = new Snip.Routers.AppointmentsRouter({appointments: []})
Backbone.history.start()