gpt4 book ai didi

javascript - 使用 ClientScript 类将 VB.net 数组传递给 javascript

转载 作者:行者123 更新时间:2023-11-28 09:31:07 26 4
gpt4 key购买 nike

我正在尝试使用 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;

}

关于javascript - 使用 ClientScript 类将 VB.net 数组传递给 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13707613/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com