I want to map a jagged array from pagemethod to JavaScript. Can anyone give me an example?
My jagged array from webmethod is:
<WebMethod()> _
<ScriptMethod()> _
Public Shared Function multiTable(ByVal para() As Object, ByVal spname As String) As Object(,)
Dim dsrt As New DataSet, dbacc As New dataaccess
dsrt = dbacc.retds1(spname, conn, para)
Dim arr()() As Object = New Object(dsrt.Tables.Count - 1)() {}
For i As Integer = 0 To dsrt.Tables.Count - 1
arr(i) = New Object(dsrt.Tables(i).Columns.Count - 1) {}
For j As Integer = 0 To dsrt.Tables(i).Columns.Count - 1
arr(i)(j) = dsrt.Tables(i).Rows(i)(j)
Next
Next
End Function
I don't know how to translate it to JavaScript, but here is the code I've tried:
function success(result)
{
var dsrp2 =[];
if(result.length == 0)
{
dsrp2.length=0;
}
else
{
var ind = 0;var col=(result.length/2); // i guess here only i should make change
for (i=0;i<2;i++)
{
var data=[];
for (j=0;j<col-1;j++)
{
data.push(result[ind]);
ind++;
}
dsrp2.push(data);
}
}
}
Web method:
<WebMethod()> _
<ScriptMethod()> _
Public Shared Function multiTable(ByVal para() As Object, ByVal spname As String) As Object()()
Dim dsrt As New DataSet, dbacc As New dataaccess
dsrt = dbacc.retds1(spname, conn, para)
Dim arr()() As Object = New Object(dsrt.Tables.Count - 1)() {}
For i As Integer = 0 To dsrt.Tables.Count - 1
If dsrt.Tables(i).Rows.Count = 0 Then
arr(i) = New Object(0)() {}
Continue For
Else
arr(i) = New Object(dsrt.Tables(i).Columns.Count - 1) {}
For j As Integer = 0 To dsrt.Tables(i).Columns.Count - 1
arr(i)(j) = dsrt.Tables(i).Rows(0)(j)
Next
End If
Next
Return arr
End Function
Javascript:
function success(result)
{
var dsrp2 =new Array();
dsrp2=result;
}