Jump to content

Backbone newbie question


CtnChainsaw

Recommended Posts

Hi all,

 

I'm new to backbone and JQuery and I'm trying to get my head around it.  I'm doing exercise 2 from this book:

 

 

http://addyosmani.github.io/backbone-fundamentals/#getting-set-up

 

 

It says "You may notice that the file input for the cover image isn’t working, but that is left as an exercise to the reader."

I've tried uploading an image and I get this in the console:

 

GET file:///C:/fakepath/dan_brown.jpg

 

 

This should be easy enough to do.

 

Anyone got any ideas?

 

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/279636-backbone-newbie-question/
Share on other sites

Something like this will do it.  However all elements then have 'img/' prepended to the content because the first if statement evaluates to true each time.

 

Anybody got any tips to sort this?

	addBook: function( e ) {
		e.preventDefault();

		var formData = {};

		$( '#addBook div' ).children( 'input' ).each( function( i, el ) {
			if( $( el ).val() != '' )
			{
				if($("#coverImage").attr("name") == 'coverImage'){
					formData[ el.id ] = 'img/' + $( el ).val(); 
				} else if ($("#coverImage").attr("name") != 'coverImage') {
					formData[ el.id ] = $( el ).val();
				}
			}
		});

		this.collection.add( new app.Book( formData ) );
	},

Sorted :)

	addBook: function( e ) {
		e.preventDefault();

		var formData = {};

		$( '#addBook div' ).children( 'input' ).each( function( i, el ) {
			if( $( el ).val() != '' )
			{
				if( el.id === 'coverImage') {
					formData[ el.id ] = 'img/' + $( el ).val(); 
				} else {
					formData[ el.id ] = $( el ).val();
				}
			}
		});

		this.collection.add( new app.Book( formData ) );
	},

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.