【问题标题】:Why won't my Handlebar lib load? - Requirejs为什么我的 Handlebar 库无法加载? - 需要
【发布时间】:2013-11-06 11:07:08
【问题描述】:

我正在尝试在 Backbone 项目中使用 requirejs-hbs 库。我在同一个文件夹中有Handlebars lib 和requirejs-hbs lib。它们在我的config 中声明相同。当我在我的 chrome 标签中查看源代码时,我只得到了 require-hbs 脚本,我没有得到 handlebars 脚本。这是我的配置文件:

require.config({
  hbs: {
    templateExtension: '.hbs'
  },
  paths: {
    backbone: "libs/backbone/backbone",
    Handlebars: 'libs/handlebars/handlebars.amd',
    hbs: 'libs/requirejs-hbs/hbs',
    jquery: 'libs/jquery/jquery',
    underscore: 'libs/underscore/underscore'
  },
  shim: {
    backbone: {
      deps: [
        'underscore',
        'jquery'
      ],
      exports: 'Backbone'
    },
    underscore: {
      exports: '_'
    }
  }
});

require(['js/router/easier.view'], function(View) {
  'use strict';

  var view = new View();
});

这是我试图访问我的模板的视图。

define(function(require) {
  'use strict';

  var Backbone = require('backbone');
  var testTemplate = require('hbs!views/test.hbs');

  var router = Backbone.View.extend({
    render: function() {
      debugger;
    }
  });

  return router;
});

我得到的错误是GET http://localhost:9000/handlebars.js 404 (Not Found)。我有我要声明的其他文件,但我没有handlebars.js。我做错了什么?

【问题讨论】:

    标签: backbone.js requirejs handlebars.js


    【解决方案1】:

    您正在创建一个到 Handlebars 的路径,但是如果您查看 requirejs-hbs 的源代码,您会发现它使用了 handlebars

    因此,要么将 requirejs-hbs 源更改为 Handlebars,要么将路径更改为 handlebars

    应该可以。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多