我有一个js代码,其中一个数组运行良好
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C"
];
Run Code Online (Sandbox Code Playgroud)
然后我在我的代码后面创建了一个数组字符串,或者在类级别上创建.cs
public static string[] test={"animal","lovely"};
Run Code Online (Sandbox Code Playgroud)
然后我将js数组更改为此
var availableTags = "<%=test%>"; // also tried without quotes
Run Code Online (Sandbox Code Playgroud)
现在我没有像以前的js数组一样的结果
使用完整的代码进行编辑,我从http://jqueryui.com/demos/autocomplete/#multiple中获取了jquery
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Web.Script.Serialization;
public partial class onecol : System.Web.UI.Page
{
JavaScriptSerializer serializer;
public static string test = "['animal','lovely']";
public static string check;
protected void Page_Load(object sender, EventArgs e)
{
serializer = new JavaScriptSerializer();
//serializer
this.detail.ToolsFile = "BasicTools.xml"; …Run Code Online (Sandbox Code Playgroud) 我有这个JS功能:
var i = 0;
for (i = 0; i < myArray.length; i++) {
alert(myArray[i]);
}
Run Code Online (Sandbox Code Playgroud)
但是myArray[]使用c#在服务器端创建:
ArrayList myArray = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
foreach (MyObject myobject in MyObjects)
{
myArray.Add(myobject.Description);
}
}
Run Code Online (Sandbox Code Playgroud)
那么,我怎样才能将C#数组"传递"给Javascript?或者我需要在服务器端打印整个javascript代码并将其发送到服务器?