JavaScript Backbone not defined with require js

I'm getting Model not defined error with below code. I've added underscore, jquery, backbone etc but I can only get object returned with console.log function for jquery only $

Is there a reason why other objects are not returning inside define function?

Below is my code from main.js:

require.config({
  paths: {
    jquery: '//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min',
    underscore: '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min',
    backbone: '//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min',
    bootstrap: '//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min',
    qunit: '//cdnjs.cloudflare.com/ajax/libs/qunit/1.11.0/qunit.min',
    bootstrapDatepicker: '/js/bootstrap-datepicker',
    backboneValidation: '//cdnjs.cloudflare.com/ajax/libs/backbone.validation/0.7.1/backbone-validation-min'
  }

});

define([
    'jquery',
    'underscore',
    'backbone',
    'bootstrap',
    'qunit',
    'bootstrapDatepicker',
    'backboneValidation'
], function($, _, Backbone, Bootstrap, Qunit, Datepicker, backboneValidation){

    $(function(){

        var ReportModel = Backbone.Model.extend({
            validation: {
                'date.from': {
                    required: true,
                    msg: 'Please enter a from date'
                },
                'date.to': {
                    required: true,
                    msg: 'Please enter a to date'
                }
            },
            initialize: function(){
                console.log('test');
            }
        });

        $('#dp3').datepicker().on('changeDate', function(e){
            $('#toDate').datepicker('setStartDate', new Date(e.date.valueOf()));
        });
        $('#dp4').datepicker().on('changeDate', function(e){
            $('#fromDate').datepicker('setEndDate', new Date(e.date.valueOf()));
        });

    });
});
Answer:1

Use shim config: http://requirejs.org/docs/api.html#config-shim. Example:

requirejs.config({
    paths: {
        jquery: '//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min',
        underscore: '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min',
        backbone: '//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min',
    },
    shim: {
        backbone: {
            //These script dependencies should be loaded before loading backbone.js
            deps: ['underscore', 'jquery'],
            //Once loaded, use the global 'Backbone' as the module value.
            exports: 'Backbone'
        },
        underscore: {
            exports: '_'
        },
    }
});
Answer:2

I'm trying to set up a tabbed navigation bar but it's not hiding the content from the other tabs. On a similar note, creating a new page doesn't work in the same way. It shows the content of the ...

I'm trying to set up a tabbed navigation bar but it's not hiding the content from the other tabs. On a similar note, creating a new page doesn't work in the same way. It shows the content of the ...

  1. jquery mobile tabs swipe
  2. jquery mobile tabs example
  3. jquery mobile tabs default active
  4. jquery mobile tabs
  5. jquery mobile tabs not working
  6. jquery mobile tabs active
  7. jquery mobile tabs w3schools
  8. jquery mobile tabs menu swipe
  9. jquery mobile tabs events
  10. jquery mobile scrollable tabs
  11. jquery mobile navbar tabs example
  12. jquery ui tabs mobile
  13. jquery mobile horizontal scroll tabs

I've got a content-editable <div>. When a correct markdown syntax is entered into the div, I need it to add the correct HTML around the outside, but preserve the markdown characters within. For ...

I've got a content-editable <div>. When a correct markdown syntax is entered into the div, I need it to add the correct HTML around the outside, but preserve the markdown characters within. For ...

Use Case : I have a webpage which shows popovers for some of the functionalities. The popovers can be considered to be a HTML div which is shown when the corresponding button is clicked. And again go ...

Use Case : I have a webpage which shows popovers for some of the functionalities. The popovers can be considered to be a HTML div which is shown when the corresponding button is clicked. And again go ...

  1. change browser back button url
  2. change browser back button behaviour
  3. change browser back to english
  4. change browser back to google
  5. change browser back
  6. javascript change browser back button behavior
  7. change default browser back to internet explorer
  8. change google browser back to english
  9. change my browser back to english
  10. php change browser back button
  11. javascript change browser back button
  12. change default browser back

If you render the code below in chrome, you will see this adds fine but if you use IE, the rows doesn't get added. Could you tell me what am I doing wrong here that its not working in IE? When I add a ...

If you render the code below in chrome, you will see this adds fine but if you use IE, the rows doesn't get added. Could you tell me what am I doing wrong here that its not working in IE? When I add a ...

  1. javascript works in chrome but not ie
  2. javascript works on chrome but not firefox
  3. javascript works in chrome but not internet explorer
  4. javascript works on chrome not ie
  5. javascript works in chrome but not edge
  6. javascript works in chrome debugger
  7. javascript only works in chrome