且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法读取属性未定义“查看”

更新时间:2022-05-08 21:28:25

骨干,并强调不是AMD兼容。缺省情况下,它们不提供与RequireJS兼容的接口。

Backbone and Underscore are not AMD-compliant. By default, they don't provide an interface compatible with RequireJS.

在最后一个版本,RequireJS 提供解决问题的一个有用的方法:

In last versions, RequireJS provide a useful way to solve the problem:

您main.js:

require.config({
  shim: {
    underscore: {
      exports: '_'
    },
    backbone: {
      deps: ['underscore', 'jquery'],
      exports: 'Backbone'
    }
  },
  paths: {
    jquery: 'lib/jquery-min',
    underscore: 'lib/underscore-min',
    backbone: 'lib/backbone-min',
    templates: '../templates'
  }

});

require([
  'app'
], function(App){
  App.initialize();
});