如何从SQL SELECT查询中的c#变量创建jQuery数组
when my page loads I run a SQL SELECT to get a c# variable
当我的页面加载时,我运行一个SQL SELECT来获得一个c#变量
var row = db.QuerySingle(myquery, someID);
var positionTags = row.PosTag;
the result is in the form:
结果是以下形式:
"tag1,tag2,tag3,..."
I'm try to get this to a jquery Array with elements separated by the commas with the following
我试着把它变成一个jquery数组,其元素用逗号分隔,并带有以下内容
var positionTagsJS = ['@positionTags'];
however positionTagsJS shows up as an array with just 1 element.
但是positionTagsJS显示为只有1个元素的数组。
tag1,tag2,tag3,...
I also tried to create an array from my initial c# variable as follows:
我还尝试从我的初始c#变量创建一个数组,如下所示:
Array positionTagsArray = positionTags.Split(',');
positionTags = new JavaScriptSerializer().Serialize(positionTagsArray);
This leaves me with something in the form:
这给我留下了以下形式:
"[\"tag1\",\"tag2\",\"tag3\",\"...\"]"
and when I run it through my script
当我通过我的脚本运行它
var positionTagsJS = ['@positionTags'];
I get...
["tag1","tag2","tag3","..."]
So, what is the most efficient way to get a java script and/or jQuery array of the form
那么,获取表单的java脚本和/或jQuery数组的最有效方法是什么
["tag1","tag2","tag3","..."]
It probably doesn't matter but ultimately this array will be used to activate a jQuery UI selecatables widget.
它可能没关系,但最终这个数组将用于激活jQuery UI selecatables小部件。
1 个解决方案
#1
0
I would do the second option, but assign the value like this:
我会做第二个选项,但是像这样分配值:
var positionTagsJS = @Html.Raw(positionTags);
更多相关文章
- 将CSS样式转换成JS变量?
- 使用php变量用ajax更新jqplot
- 导入地址簿联系人,存储在数组中并保存到数据库
- jquery解析php通过ajax传过来的json二维数组对象
- 从ajax查询返回的数组看起来还可以,但是它的器官没有正常显示
- JQuery攻略(三)数组与字符串
- jquery done()不能获取外部变量
- 使用window.open将变量传递给新的HTML
- 如何在localStorage中存储数组?(复制)