Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an object that holds an array of theme objects ...

JavaScript
themesHolder = { themes:[] };


Now i want to add data to this object dynamically.. i have done this
JavaScript
var themeName = $("input[name='themeName']").val().trim(),
	themeFileName =  $("input[name='themeFilename']").val().trim(),
	themeDefault =  $("input[name='themeDefault']:checked").val().trim(),
	currentThemeData = {};
			
if( themeName =="" || themeFileName==""){
	alert("Please make sure theme name and filename is supplied");
}else{
	// continue with processing of the theme data...
	currentThemeData["name"] = 	themeName;
	currentThemeData["filename"] = 	themeFileName;
	currentThemeData["isDefault"] = themeDefault;
	
	++counter;
	themesHolder.themes.push( currentThemeData );
	
}


The challenge that i am facing is that when i am splicing the data from this object, the results does not disappear..

Anybody who can help me out with a code on the safe way to delete a theme entry given the name or filename..
Thanks.
Posted

1 solution

I added some fixes to my function and it worked just fine...

This is what i did
...

calling the delete function from the delete button ..

JavaScript
links = "<button type=\"button\" onclick=\"deleteTheme('"+rowId+"','"+name+"')\">Del</button>";


the rowId - will represent the current table tr/row - such that if i delete the value, i should also delete the row.

the Name - represents the theme name i want to delete.

And the delete method...
JavaScript
	deleteTheme = function( rowId, value ){
		themesHolder.themes.removeValue("name", value );
		deleteRow( rowId );
		updateThemeBox();
	}


Array.prototype.removeValue = function( propertName, value ){
		
	for( var i=0; i<this.length;>		
		if( this[i].name == value	){			
			this.splice( i, 1 );
		}
	}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900