this.listenTo( this.collection, 'add', this.renderBook );
renderBook: function( item ) { console.log("this is renderBook"); var bookView = new app.BookView({ model: item }); this.$el.append( bookView.render().el ); },
events:{ 'click #add':'addBook' }, addBook: function( e ) { console.log("This is event mathod"); e.preventDefault(); var formData = {}; $( '#addBook div' ).children( 'input' ).each( function( i, el ) { if( $( el ).val() != '' ){ formData[ el.id ] = $( el ).val(); } }); this.collection.add( new app.Book( formData ) ); console.log(JSON.stringify(formData)); },
this code is not working......
this.listenTo( this.collection, 'add', this.renderBook );
renderBook: function( item ) {
console.log("this is renderBook");
var bookView = new app.BookView({
model: item
});
this.$el.append( bookView.render().el );
},
events:{
'click #add':'addBook'
},
addBook: function( e ) {
console.log("This is event mathod");
e.preventDefault();
var formData = {};
$( '#addBook div' ).children( 'input' ).each( function( i, el ) {
if( $( el ).val() != '' ){
formData[ el.id ] = $( el ).val();
}
});
this.collection.add( new app.Book( formData ) );
console.log(JSON.stringify(formData));
},
this code is not working......