Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从IList列表中填充Jquery数组_Jquery_Ajax - Fatal编程技术网

从IList列表中填充Jquery数组

从IList列表中填充Jquery数组,jquery,ajax,Jquery,Ajax,我想用从后端函数填充的几个名称填充jquery数组。 以下是脚本: var availableTags = '@Url.Action("PopSearch", "Home")'; $("#searchtxt").autocomplete({ source: availableTags }); public ActionResult PopSearch() { IndustryManager manager = new IndustryM

我想用从后端函数填充的几个名称填充jquery数组。 以下是脚本:

 var availableTags = '@Url.Action("PopSearch", "Home")';
    $("#searchtxt").autocomplete({
        source: availableTags
    });

public ActionResult PopSearch()
    {
        IndustryManager manager = new IndustryManager();
        ProductRangeManager manager2 = new ProductRangeManager();
        ProductCategoryManager manager3 = new ProductCategoryManager();

        IList<Industry> industryList = manager.GetIndustries();
        IList<ProductRange> rangeList = manager2.GetAllProductRanges();
        IList<ProductCategory> categoryList = manager3.GetAllProductCategories();

为了获得更好的性能,您可以在服务器端预筛选数据,并在单个数组中返回数据。在客户端,修改以使用以下内容非常简单:

更新:您可以组合如下值:

var result = industryList.Select(x => x.Name)
                 .Union(rangeList.Select(x => x.Name))
                 .Union(categoryList.Select(x => x.Name)).ToArray();

为什么不将服务器端的名称提取并交付为一个列表而不是三个呢?您可以使用linq将其组合起来。也许这不是一个最好的解决方案,但我添加了示例。只添加了第一个列表?奇怪的事情发生了,所有的项目都被添加了,但只有三个最上面的项目显示出来,这就是为什么我想先填充数组,然后将其设置为源,而不是继续调用函数。您可以使用ajax request$.ajax和store array in variable调用action,它将像datasource一样使用。
var result = industryList.Select(x => x.Name)
                 .Union(rangeList.Select(x => x.Name))
                 .Union(categoryList.Select(x => x.Name)).ToArray();