1
votes

I'm new to Backbone.js and i'm using it for a data visualization, as a school project. I've implemented require.js after some weeks of work, following this tutorial: http://backbonetutorials.com/organizing-backbone-using-modules/

I've reorganized my code then, but now i got an error that i'm not able to fix... I use Datamaps (http://datamaps.github.io/) to create a world map. I passed the needed scripts in the require define() function, but i'm probably doing something wrong.

Here is the code part which provide the error :

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({ ... })
...

And the browser respond with "Uncaught ReferenceError: Datamap is not defined". It was working before, and since i use require, it doesn't work anymore, i've probably missed a param or something else.

I would appreciate some help on this ;)

Thank you in advance!

1
Your dependencies do not match your function arguments in the code you've posted (after d3 -> mapTemplate)source.rar
Oh well, you got it :) Thank you! I read the define() doc on require, and in fact i didn't understand what i really does, i thought it was only to load the scripts.ClementParis016

1 Answers

1
votes

With RequireJS when you define a module with dependencies, the dependencies are passed as arguments to your module definition function. Hence you need to match them. For e.g.,

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 ...
});