[英]passing VB.net array to javascript using ClientScript class
我正在嘗試使用ASP.net類ClientScript將數組傳遞給我的aspx頁面。 我已經成功完成了一個較早的示例來完成此操作(下面的代碼示例)。 但是新的例程不起作用。 區別在於ClientScript類。
錯誤指出“ routeCoords未定義”
我的Java代碼是...
function newTest() {
var myArray = [ , ];
var n = 0;
var recCount = routeCoords.length / 15;
for (var i = 0; i < recCount ; i++) {
for (var s = 0; s < 15; s++) {
myArray[i, s] = routeCoords[n];
n++;
alert(myArray[s], [i]);
}
}
}
vb.net建立數組並注冊腳本。
' arrylist
For p = 0 To arryLst.Count - 1
Page.ClientScript.RegisterArrayDeclaration("routeCoords", arryLst(p))
Next
Dim strScript As String = "newTest();"
ClientScript.RegisterStartupScript(GetType(Page), "newTest", strScript.ToString, True)
該陣列在vb.net中正確填充
這是正在運行的樣本中的例程...
VB.net代碼:
For s = 0 To arryLst.Count - 1
Page.ClientScript.RegisterArrayDeclaration("parmTypeAry", arryLst(s))
Next
JAVA代碼:
// Create and Element Object of type "option"
var opt = document.createElement("option");
//Add the option element to the select item
listID.options.add(opt);
//Reading Element From Array
opt.text = parmTypeAry[s];
它會填充一個下拉列表框。
這是解決方案。 它需要在for循環中使用IF條件來檢查陣列。
for (i = 0; i < recCount; i++) {
// Array of arrays builds out each record.
if (!myArray[i])
myArray[i] = []
for (s = 0; s < 16; s++) {
// myArray[i] = new Array(14);
myArray[i][s] = routeCoordsAry[n];
n++;
// alert("i=" + i + " s=" + s + " Val: " + (myArray[i][s]));
}
// var u = 4;
s = 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.