[英]asp.net razor and jQuery autocomplete plugin
Hey i want to autocomplete this html text input: 嘿,我想自动完成这个HTML文本输入:
$("#Supplier").autocomplete({
source: availableTags
});
and i have array of strings came from the controller to the view: 我有从控制器到视图的字符串数组:
@ViewBag.VendorsArray
I can use it like this: 我可以像这样使用它:
var availableTags = @ViewBag.VendorsArray;
and than use is in the "source" option of the autocomplete plugin? 而且使用是在自动完成插件的“源”选项? Its didnt work for me.
它对我没有用。 Just if i make manually arrray like this:
就像我手动制作这样的:
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC"
];
Than, its work. 比,它的工作。
At first pass a coma separated string your ViewBag object then set to a javascript variable then convert the variable to javascript array. 首先传递一个逗号分隔的字符串,然后将ViewBag对象设置为javascript变量,然后将变量转换为javascript数组。
Please flow the example: 请流动示例:
@{ViewBag.VendorsArray = "ActionScript,AppleScript,Asp,BASIC";} @ {ViewBag.VendorsArray =“ActionScript,AppleScript,Asp,BASIC”;}
<script>
var list = "@ViewBag.VendorsArray";
var availableTags = list.split(',');
$("#Supplier").autocomplete({
source: availableTags
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.