OK, I am getting my ass kicked by this problem. I am storing class instantiated objects into an associative array and one of two things is happening after adding the objects to the associative array
only the last object added is available, or
all of the associated indices have the same value as the last object added.
I have verified that the data that is coming in from the XML file and being pushed into into the object just prior to adding it to the associative array and it is fine, but after adding it to the associative array (declared using new Object() )... it is all messed up.
Here is an example of the code I am working with:
Associative Array
var arrObjList = new Object();
arrObjList = ProcessObjectList(); // see function declaration below
Adding the Class Objects to the Associative Array from above
ProcessObjectList = function (inXML)
{
var arrObjectList = new Object();
var objClass = new clsNewClass(); // see class declaration below
nodes = inXML.getElementsByTagName('thing');
for (ctr=0; ctr < nodes.length; ctr++)
{
objClass.seName ( nodes[ctr].getAttributeNode('name').nodeValue );
objClass.setValue1 ( nodes[ctr].getAttributeNode('value1').nodeValue );
objClass.setValue2 ( nodes[ctr].getAttributeNode('value2').nodeValue );
arrObjectList[ objClass.geName() ] = objClass;
} /* end for loop */
return arrObjectList;
} /* end Process Object List */
Class Code
function clsNewClass()
{
var Name = '';
var Value1 = '';
var Value2 = '';
this.geName = function() { return Name; }
this.getValue1 = function() { return Value1; }
this.getValue2 = function() { return Value2; }
this.setName = function(inVal) { Name = inVal; }
this.setValue1 = function(inVal) { Value1 = inVal; }
this.setValue2 = function(inVal) { Value2 = inVal; }
} // end class New Class
So what do you think. I have a lot of coding that is stalled by this. I do not code for a living, and at some point I will pull out jquery or prototypejs and convert things over, but that is not what I am looking for right now. I tried this by declaring the may associative array in the following ways, none of which worked: new Array(), new Object(), and Object();
Thanks guys.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.