BackboneJS - Cannot call method 'on' of undefined

Sysrq147

I have this simple BackboneJS app and it keeps returning this error on adding new model to collection: Cannot call method 'on' of undefined. Can someone help me. I can't see the problem in here.I have my templates defined in index.html, and I am using Slim framework and NotORM.

 (function(){

    window.App = 
    {
      Models:{},
      Collections: {},
      Views : {}
    }

    window.template = function(id) 
    {
    return _.template( jQuery('#' + id).html());
    }

    App.Models.Party = Backbone.Model.extend({


    });

    App.Collections.Partys = Backbone.Collection.extend({

       model: App.Models.Party,
       url: "http://localhost/BackboneJS/vjezba6/server/index.php/task"  
    });

    App.Views.Party = Backbone.View.extend({

        tagName :"div",
        className: "box shadow aktivan",
        template: template("boxovi"),

        initialize: function()
        {
            this.model.on('change', this.render, this);
        },  

        events:{

            "click .izbrisi" : "izbrisi"
        },

        render: function() 
        {
        var template = this.template( this.model.toJSON() );

        this.$el.html(template);

        return this;
        },

        izbrisi: function()
        {
            this.model.destroy();
        },

        ukloni: function()
        {
            this.remove();
        }



    });

    App.Views.Partys = Backbone.View.extend({


      tagName:"div",
      id: "nosac-boxova",

      initialize: function()
      {

      },

    render: function() {
        this.collection.each(this.addOne, this);

        return this;
    },

    addOne: function(party) {
        var partyView = new App.Views.Party({ model: party });
        this.$el.append(partyView.render().el);
    }

    });

    App.Views.Dodaj = Backbone.View.extend({

        tagName: "div",
        template : template("dodajTemp"),
        events:
        {
            'submit' : 'submit'
        },

        submit : function(e)
        {
            e.preventDefault();
            console.log(e);
            var nazivPolje = $(e.currentTarget).find(".naziv").val();   
            var tekstPolje = $(e.currentTarget).find(".lokal").val();   

            var noviParty = new App.Views.Party({naziv:nazivPolje, tekst: tekstPolje});
            this.collection.create(noviParty);
        },

        initialize: function()
        {

        },

        render: function()
        {
            var template = this.template();
            this.$el.html(template);
            return this;
        }

    });


/*   var kolekcijaPartya = new App.Collections.Partys([

      {
         naziv:"Ovo je prvi naziv",
         tekst: "Ovo je prvi tekst"
      },
       {
         naziv:"Ovo je drugi naziv",
         tekst: "Ovo je drugi tekst"
      }

    ]);*/

   var kolekcijaPartya = new App.Collections.Partys;
   kolekcijaPartya.fetch({

    success: function()
    {

        var partysView = new App.Views.Partys({collection:kolekcijaPartya});
        $("#content").prepend(partysView.render().el);
        $("div.box").slideAj();


        var dodajView = new App.Views.Dodaj({collection: kolekcijaPartya});
         $("div#sidebar-right").html(dodajView.render().el);
    }




   });




})();
Yurui Zhang
var noviParty = new App.Views.Party({naziv:nazivPolje, tekst: tekstPolje});
this.collection.create(noviParty);

so you are trying to add a View to your collection?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

TypeError: Cannot call method 'then' of undefined

From Dev

Cannot call method 'use' of undefined

From Dev

Javascript: Cannot call method of undefined

From Dev

Cannot call method 'use' of undefined

From Dev

TypeError: Cannot call method of undefined

From Dev

"Cannot call method 'transaction' of undefined" error in indexedDB

From Dev

Uncaught TypeError: Cannot call method 'getLocalName' of undefined

From Dev

AngularJS and Karma, Cannot call method 'module' of undefined

From Dev

Cannot call method 'match' of undefined handlebar issue

From Dev

Karma error Cannot call method 'module' of undefined

From Dev

ionicModal Cannot call method 'fromTemplateUrl' of undefined

From Dev

TypeError: Cannot call method 'click' of undefined

From Dev

TypeError: Cannot call method 'get' of undefined

From Dev

Meteor and CoffeeScript: Cannot call method 'helpers' of undefined

From Dev

TypeError: Cannot call method 'toLowerCase' of undefined

From Dev

Uncaught TypeError: Cannot call method 'match' of undefined

From Dev

Uncaught TypeError: Cannot call method 'getRootNode' of undefined

From Dev

TypeError: Cannot call method 'replace' of undefined

From Dev

AngularJS Cannot call method 'getValue' of undefined

From Dev

Npm: Cannot call method 'charAt' of undefined

From Dev

TypeError: Cannot call method 'charCodeAt' of undefined

From Dev

Cannot call method 'toLowerCase' of undefined (Bootstrap Typeahead)

From Dev

Quintus engine,Cannot call method 'draw' of undefined

From Dev

Uncaught TypeError: Cannot call method 'getRootNode' of undefined

From Dev

javascript Cannot call method undefined in getElementsByTagName

From Dev

Meteor and CoffeeScript: Cannot call method 'helpers' of undefined

From Dev

AngularJS Cannot call method 'getValue' of undefined

From Dev

TypeError: Cannot call method 'replace' of undefined

From Dev

AngularJS and Karma, Cannot call method 'module' of undefined

Related Related

  1. 1

    TypeError: Cannot call method 'then' of undefined

  2. 2

    Cannot call method 'use' of undefined

  3. 3

    Javascript: Cannot call method of undefined

  4. 4

    Cannot call method 'use' of undefined

  5. 5

    TypeError: Cannot call method of undefined

  6. 6

    "Cannot call method 'transaction' of undefined" error in indexedDB

  7. 7

    Uncaught TypeError: Cannot call method 'getLocalName' of undefined

  8. 8

    AngularJS and Karma, Cannot call method 'module' of undefined

  9. 9

    Cannot call method 'match' of undefined handlebar issue

  10. 10

    Karma error Cannot call method 'module' of undefined

  11. 11

    ionicModal Cannot call method 'fromTemplateUrl' of undefined

  12. 12

    TypeError: Cannot call method 'click' of undefined

  13. 13

    TypeError: Cannot call method 'get' of undefined

  14. 14

    Meteor and CoffeeScript: Cannot call method 'helpers' of undefined

  15. 15

    TypeError: Cannot call method 'toLowerCase' of undefined

  16. 16

    Uncaught TypeError: Cannot call method 'match' of undefined

  17. 17

    Uncaught TypeError: Cannot call method 'getRootNode' of undefined

  18. 18

    TypeError: Cannot call method 'replace' of undefined

  19. 19

    AngularJS Cannot call method 'getValue' of undefined

  20. 20

    Npm: Cannot call method 'charAt' of undefined

  21. 21

    TypeError: Cannot call method 'charCodeAt' of undefined

  22. 22

    Cannot call method 'toLowerCase' of undefined (Bootstrap Typeahead)

  23. 23

    Quintus engine,Cannot call method 'draw' of undefined

  24. 24

    Uncaught TypeError: Cannot call method 'getRootNode' of undefined

  25. 25

    javascript Cannot call method undefined in getElementsByTagName

  26. 26

    Meteor and CoffeeScript: Cannot call method 'helpers' of undefined

  27. 27

    AngularJS Cannot call method 'getValue' of undefined

  28. 28

    TypeError: Cannot call method 'replace' of undefined

  29. 29

    AngularJS and Karma, Cannot call method 'module' of undefined

HotTag

Archive