BackboneJS - Cannot call method 'on' of undefined

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);
    }




   });




})();

Answers


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?


Need Your Help

Django: path to static file is wrong in generated HTML

django django-templates django-staticfiles

I have some javascript that I would like to run on a particular page of a Django site I am building. In the template I currently have: