我想将一个锯齿状数组从pagemethod映射到JavaScript。谁能举个例子呢?
来自webmethod的锯齿状数组是:
<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
我不知道如何将其翻译为JavaScript,但这是我尝试过的代码:
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);
}
}
}
答案 0 :(得分:0)
网络方法:
<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;
}