0

I have been working on a new project for sometime and recently started using require.js in the project.

It all seemed to work fine until I tried making a call from application.js to dashboard.js when the tab #dailyTab or #weeklyTab was clicked or access varialbe var a in dashboard,js. My code is below

main.js

requirejs.config({
    baseUrl : '../static/js/',
    paths : {
        'jquery' : 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min',
        'jquery-ui' : 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min',
        'bootstrap' : ['//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min', 'bootstrap.min'],
    },
    shim : {
        'bootstrap' : ['jquery'],
        'bootswatch' : ['bootstrap'],
    }
});

require(["jquery", "jquery-ui", "bootstrap", "dashboard", "application"], function($, jui, bootstrap, dashboard, application) {
    $("#myTab a:first").tab("show");
}, function(err) {
    console.log(err)
});

dashboard.js

define(function() {
    var a = 10;
    var Reload = {
        dailyCharts : function() {
            console.log("Daily Charts");
        },
        weeklyCharts : function() {
            console.log("Weekly Charts");
        }
    };
    var Display = {
        none : function(node) {
            console.log("none");
        },
        block : function(node) {
            console.log("block");
        }
    }
});

application.js

define(["jquery", "dashboard"], function(jquery, dashboard) {
    $("#dailyTab").click(function() {
        dashboard.Reload.dailyCharts();
    });
    $("#weeklyTab").click(function() {
        dashboard.Reload.weeklyCharts();
    });
});

Can someone tell me what I have done wrong or what I can do to fix this issue. I accept my coding skills is not very good.

Any help on this is much appreciated. Thanks in advance

1 Answer 1

2

Well, your dashboard.js didn't return anything. How would application.js use it?

define(function() {
    var a = 10;
    var Reload : {...};
    var Display : {...};
    //return the interface
    return {
      Reload : Reload,
      Display : Display
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

Earlier I tried wrapping them all together with a return {} , let me try putting the variables out of the block.
@shabeer90 you can return an object of references. You need not move all of the code into the returned object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.