RequireJS - custom js-library not working

2019-08-31 04:19发布

问题:

I'm trying to include a custom js-library/script in my RequireJS-config but it doesnt seem to work. So I hope someone can help me out. I'm using RequireJS in combination with Backbone and Handlebars, so just to mention it...

In my Require config I have:

require.config({

paths: {

    jquery: 'lib/jquery/jquery',
    backbone: 'lib/backbone/backbone',

    // Templating.
    handlebars: 'lib/handlebars/handlebars',

    // Plugins.
    jqueryEffects: 'lib/jquery/jquery.effects',
    ... //some more libraries

},

shim: {
    backbone: {
        deps: ['jquery', 'lodash','jqueryEffects'],
        exports: 'Backbone'
    },
    lodash: {
        exports: '_'
    },
    handlebars: {
        exports: 'Handlebars'
    },
    jqueryEffects : {
        deps: ['jquery']
    }
  }
});

The jquery.effects.js is a simple script i created my own to handle special click events or run animations etc. When i start to run my backbone app, the console tells me that the script is loaded. So now on one of my Views, I have rendered a HTML file which contains an anchor with a class which serves as an identifier, which after clicking it should trigger something...BUT, nothing happens, so I tried to make an alert in the jquery.effects.js-file:

$(function() {
 alert($(".videoname").lenght);
});

This gave me the response undefined. Does anyone maybe have an idea? The same goes when I add more libraries, console says they are loaded, but nothing happens... ?!?!?!??

回答1:

try this (length not lenght) :

(function() {
    alert($(".videoname").length);
})();

That's means that your script is working ;)