Say I have object:
function obj()
{
this.prop1;
this.prop2;
this.prop3;
}
and an array of obj's
objects = [new obj(),new obj(),new obj()];
I want to easily iterate through each using jquery where the class name is equivalent to the property of the object.
var itemsIWantToBind = ["prop1","prop2","prop3"];
for(j=0;j<itemsIWantToBind.length;j++)
{
$("."+itemsIWantToBind[j]).unbind().blur(function(){
var id = $(this).siblings(".objID").html();
if(id >= 0)
{
objects[id].itemsIWantToBind[j] = $(this).text());
}
});
}
My issue is I want to be able use a variable variable to iterate through the items for this
objects[id].itemsIWantToBind[j] = $(this).text());
^^^^^^^^^^^^^^^^^
the indicated part does not correctly bind the value of the array item as it is trying to bind the property name of it instead.
In php it would be the same as:
foreach($itemsIwantToBind as $item)
{
$objects[$id]->$item = "Something";
}
Is there a simple way to do this in JavaScript?