- I edit my code again and I got the following 2 error :
1) Complex_collection is not defined
model: Complex_model
2) Complex_model is not defined
model: Complex_model
I am using backbone js following is my code and I done this by using backbone.js but my code is not running I want separate model , view and controller using backbone js
//model
(function(){ var Complex_model = Backbone.Model.extend({
sync:function() {},
validate:function() {},
url:function() {},
defaults :{
name : null
}
});})(this);
//view
(function(){
FriendView = Backbone.View.extend({
events :{
'click #add-input' : 'add'
},
initialize: function(){
this.collection = new Complex_collection(); // This is collection
_.bindAll(this, 'render');
},
add : function() {
alert("hello");
var friend_name = $('#input').val();
this.collection.add({ name : friend_name });
},
render : function(){
$("#friends-list").append("<li>"+ model.get("name")+"</li>");
},
});
var view = new FriendView(); })(this);
//collection
(function(){
var Complex_collection = Backbone.Collection.extend({
model: Complex_model
});})(this);
thank you
You should not create new instance of the same object in the initialize code, your code should look something like this :