--Below is a more specific test case for you. Just copy and paste it into a black HTML document and you will see. =(
<html>
<head>
<meta charset="utf-8">
<script>
var ProcessObjectList = function (inXML)
{
var arrObjectList = new Object();
var objClass = new clsNewClass(); // see class declaration below
document.write('<p> <strong> In function POL</strong></p>');
for (ctr=0; ctr <= 2; ctr++)
{
if (ctr == 0)
{
objClass.setName ('Name 1');
objClass.setValue1 ( 1 );
objClass.setValue2 ( 2 );
}
if (ctr == 1)
{
objClass.setName ( 'Name 2' );
objClass.setValue1 ( 3 );
objClass.setValue2 ( 4 );
}
if (ctr == 2)
{
objClass.setName ( 'Name 3' );
objClass.setValue1 ( 5 );
objClass.setValue2 ( 6 );
}
arrObjectList[ objClass.getName() ] = objClass;
document.write('<p> Name: <strong>' + objClass.getName() + ' </strong></p>');
} /* end for loop */
return arrObjectList;
} /* end Process Object List */
function clsNewClass()
{
var Name = '';
var Value1 = '';
var Value2 = '';
this.getName = 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
var arrObjList = Object(); // will be used for the associative array
arrObjList = ProcessObjectList(); // see function declaration below
document.write('<p> <strong> After Assignment</strong></p>');
document.write('<p> Name: <strong>' + arrObjList['Name 1'].getName() + '</strong> v1: <strong>' + arrObjList['Name 1'].getValue1() + '</strong> v2: <strong>' + arrObjList['Name 1'].getValue2() + '</strong></p>');
document.write('<p> Name: <strong>' + arrObjList['Name 2'].getName() + '</strong> v1: <strong>' + arrObjList['Name 2'].getValue1() + '</strong> v2: <strong>' + arrObjList['Name 2'].getValue2() + '</strong></p>');
document.write('<p> Name: <strong>' + arrObjList['Name 3'].getName() + '</strong> v1: <strong>' + arrObjList['Name 3'].getValue1() + '</strong> v2: <strong>' + arrObjList['Name 3'].getValue2() + '</strong></p>');
</script>
</head>
<body>
</body>
Re: Storing Objects in an Associative Array (object)
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.