我对模板文件使用.jst扩展名,并使用requirejs文本加载它们!插入.例如.,
define([ 'jquery','backbone','underscore','text!templates/MyView.jst' ],function($,Backbone,_,templateText) { return Backbone.View.extend({ template: _.template(templateText),initialize: function() { },render: function() { } }); });
当我在本地测试时,这会起作用.但是,当我在将静态文件部署到AWS(应用程序的动态部分在Heroku上运行)后尝试执行此操作时,它无法加载.jst文件并且似乎试图将.js附加到他们的网址.
供参考,这是我的requirejs配置(来自main.js)
requirejs.config({ paths: { //directories plugins: "lib/plugins",//libs jquery: "lib/jquery/1.7.1/jquery",underscore: "lib/underscore/1.3.3/underscore",backbone: "lib/backbone/0.9.2/backbone",moment: "lib/moment",// date lib //require plugins text: "lib/require/plugins/text",domReady: "lib/require/plugins/domReady" },shim: { //specify all non-AMD javascript files here. backbone: { deps: ['underscore','jquery'],exports: 'Backbone' },underscore: { exports: '_' },moment: { exports: 'moment' },'plugins/jquery.colorBox': ['jquery'],'util/jquery.dropTree':['jquery'],'util/common':['jquery'] } });