我在代码隐藏中有这些数据,并试图以各种格式将其传递给 javascript 函数:列表数组、json 字符串,但无法通过 javascript var 对象获取数据。这里最后的数据格式在后面的代码中:
List<string>[] array2 = new List<string>[listLenght];
array2.Initialize();
for (int ii = 0; ii < listLenght; ii++)
{
array2[ii] = new List<string>();
array2[ii].Add(Convert.ToString(dt.Rows[ii][5]));
array2[ii].Add(Convert.ToString(dt.Rows[ii][9]));
array2[ii].Add(Convert.ToString(dt.Rows[ii][10]));
array2[ii].Add(Convert.ToString(dt.Rows[ii][11]));
}
然后尝试以这种方式调用javascriot:
string createArrayScript = string.Format("var array2 = [{0},{1},{2},{3}];", string.Join(",",",",",", array2));
但返回错误:用户代码未处理 FormatException 索引(从零开始)必须大于或等于零且小于主题列表的大小。
这是对函数的调用: Page.ClientScript.RegisterStartupScript(this.GetType(), "registerPoiArray", createArrayScript, true);
这里是 javascript var 格式:
var markers = Poi;
var markers = [
{
"title": "via Andria, Roma",
"lat": 41.8902643,
"lng": 12.6638589,
"description": "fdsad"
},
{
"title": "via canosa, Roma",
"lat": 41.8838417,
"lng": 12.5438227,
"description": "fdsad"
},
{
"title": "via taranto, Milano",
"lat": 45.4383343,
"lng": 9.1505354,
"description": "fdsad"
},
{
"title": "via barletta, Roma",
"lat": 41.9102707,
"lng": 12.4580826,
"description": "fdsad"
}];
我不能在 javascript 中传递这个数组。请帮帮我