【发布时间】:2015-11-20 00:45:19
【问题描述】:
我有一个使用 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()
【问题讨论】:
-
在您定义路径的地方显示您的
require.config-function -
新开发:
JST显然应该被定义为一个数组,每个元素都是一个模板。 (我通过在我的 repo 中回到过去工作的时间来了解这一点。) -
是否愿意将此添加为答案 jason?
标签: javascript backbone.js coffeescript jst