Iam trying to build a very simple ul where u have a input box and add button , on clicking add button , text from input is appended to ul
this is my code :
HTML :
<body>
<input type="text" id="name">
<button id="add">Add</button>
<ul id="mylist"></ul>
JS :
$(function(){
var myCollection = Backbone.Collection.extend();
var myView = Backbone.View.extend({
el:$('body'),
tagName:'li',
initialize : function(e){
this.collection.bind("add",this.render,this);
},
events:{
'click #add' : 'addfoo',
'click .button':'removefoo'
},
addfoo:function(){
var myname= $('#name').val();
$('#name').val('');
console.log('name entered: '+myname);
this.collection.add({name:myname});
},
removefoo:function(){
//need the code here
},
render:function(){
$('#mylist').empty();
this.collection.each(function(model){
$('#mylist').append('<li>'+model.get('name') + "<button class='button'>"+"delete"+"</button></li>");
});
}
});
var view = new myView({collection: new myCollection()});
});
My add funcitonality is working , but when i click the button for delete , which model from collection should be deleted , iam stuck there , please help me out.Just need the code , for what do delete from collection in removefoo function.
In other word how do i get which model to be removed when button is clicked
Thank you