Backbone + Require + Datamaps:" Datamap未定义"

时间:2014-06-08 12:37:15

标签: javascript backbone.js requirejs

我是Backbone.js的新手,我将其用于数据可视化,作为学校项目。 经过几周的工作后,我按照本教程实现了require.js:http://backbonetutorials.com/organizing-backbone-using-modules/

我已经重新组织了我的代码,但现在我收到了一个我无法解决的错误...我使用Datamaps(http://datamaps.github.io/)来创建世界地图。我在require define()函数中传递了所需的脚本,但我可能做错了。

以下是提供错误的代码部分:

define([
  'jquery',
  'underscore',
  'backbone',
  'd3',
  'c3',
  'topojson',
  'datamaps',
  'jqueryui',
  'text!templates/map.html'
], function($, _, Backbone, mapTemplate){

     var MapView = Backbone.View.extend({

       el: $('.container'),

       initialize: function(){
         var _this = this;

         var map = new Datamap({ ... })
...

浏览器回复“未捕获的ReferenceError:未定义数据图”。 它以前工作,因为我使用require,它不再起作用,我可能错过了一个参数或其他东西。

我希望得到一些帮助;)

提前谢谢!

1 个答案:

答案 0 :(得分:1)

使用RequireJS定义具有依赖关系的模块时,依赖关系将作为参数传递给模块定义函数。因此你需要匹配它们。例如,

define([
  'jquery',
  'underscore',
  'backbone',
  'd3',
  'c3',
  'topojson',
  'datamaps',
  'jqueryui',
  'text!templates/map.html'
],
function($, _, Backbone, D3, C3, Topojson, Datamaps, jQueryUI) {
   // and in here you can then use the modules ...
});
相关问题