Domanda

main.js :

 requirejs.config({
   enforceDefine: true,
   paths: {
     "jquery": "libs/jquery/jquery-min",
     "underscore": "libs/underscore/underscore-min",
     "backbone": "libs/backbone/backbone-min",
     "jquery.pnotify":"libs/jquery/jquery.pnotify.min"

},
shim: {
   "underscore": {
       deps: [],
       exports: "_"
    },
   "backbone": {
       deps: ["jquery", "underscore"],
       exports: "Backbone"
    },
   "jquery.pnotify" : {
       deps : ["jquery"],
       exports : "jQuery.fn.pnotify"
    }
  }
});

View :

define(["jquery" ,
       "underscore" ,
       "backbone" ,
       "jquery.pnotify",
       "models/CartModel" ,
        ],function($ , _ , Backbone , Cart ){

var CartView = Backbone.View.extend({
    initialize: function() {
        this.updateQtyLabel("qtyCart");
    },
    el: '.addToCart-form',
    events : {
        "click #addToCart" : "addToCart"
    },
    addToCart : function (){
        $.pnotify({
            title: 'Go to Cart and Check Out',
            text: '1 item added to Cart',
            shadow:false,
            delay:1000
        });
    },
    render: function(){

    }
});
return CartView;
});

I got an error Uncaught Error: No define call for jquery.pnotify.

Any help is much appreciated.

È stato utile?

Soluzione

You've imported pnotify, but you didn't declare a variable for it. Change

function($ , _ , Backbone , Cart ){

to

function($ , _ , Backbone , pnotify, Cart ){

Note that it doesn't actually matter what you call the variable since you will never use it anyway. Strictly speaking, you don't even need to define the variable - jQuery plugins just live in the jQuery namespace, which you already have defined - except that you are using enforceDefine = true. But if you were to remove that property, you could remove the exports property on the shim configuration as well. Just make sure that any "export-less" modules are at the end, after the last module that has a true export.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top