How to create myData 2-dimensional array dynamically for a grid?
Hi, guys, I want to create a grid based on the data of an object array. Now I can only create a string for myData. I think it's not right. But in javascript, no 2-dimensional array can be used, right? My following code doesn't work, and computer complain the object is null. I think the myData is not created correctly. Thanks.
<script>
var info=new Array();
function accountdata(accName, tableID )
{
this.accName=accName ;
this.tableID=tableID;
}
info[0]=new accountdata("14210462", "tablecontent0" );
info[1]=new accountdata("14210470", "tablecontent1" );
info[2]=new accountdata("14210488", "tablecontent2" );
////////////creating myData.......////////////////////////////
var myData="";
for(i=0; i<3; i++)
{
myData=myData+
"["+
"\"" + info[i].accName + "\"," +
"\"" + info[i].tableID + "\"," +
"],";
}
myData=myData.substring(0,myData.length-1);
myData="["+myData+"]";
var myColumns = ["accountName", "TableID"];
var obj = new Active.Controls.Grid;
obj.setRowProperty("count", 20);
obj.setColumnProperty("count", 2);
obj.setDataProperty("text", function(i, j){return myData[i][j]});
obj.setColumnProperty("text", function(i){return myColumns[i]});
obj.setRowHeaderWidth("28px");
obj.setColumnHeaderHeight("20px");
obj.setAction("click", function(src){window.status = src.getItemProperty("text")});
document.write(obj);
</script>
<script>
var info=new Array();
function accountdata(accName, tableID )
{
this.accName=accName ;
this.tableID=tableID;
}
info[0]=new accountdata("14210462", "tablecontent0" );
info[1]=new accountdata("14210470", "tablecontent1" );
info[2]=new accountdata("14210488", "tablecontent2" );
////////////creating myData.......////////////////////////////
var myData="";
for(i=0; i<3; i++)
{
myData=myData+
"["+
"\"" + info[i].accName + "\"," +
"\"" + info[i].tableID + "\"," +
"],";
}
myData=myData.substring(0,myData.length-1);
myData="["+myData+"]";
var myColumns = ["accountName", "TableID"];
var obj = new Active.Controls.Grid;
obj.setRowProperty("count", 20);
obj.setColumnProperty("count", 2);
obj.setDataProperty("text", function(i, j){return myData[i][j]});
obj.setColumnProperty("text", function(i){return myColumns[i]});
obj.setRowHeaderWidth("28px");
obj.setColumnHeaderHeight("20px");
obj.setAction("click", function(src){window.status = src.getItemProperty("text")});
document.write(obj);
</script>
Jack
August 23,