2011-12-16 103 views
1

我想用後端函數填充幾個名稱來填充jquery數組。 這是腳本:從IList列表中填充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(); 
+1

爲什麼不提取和交付的名字服務器端作爲一個列表,而不是三? – tvanfosson 2011-12-16 11:52:06

回答

0

爲了更好的服務表現,你可以prepeare在服務器端的數據,並在單個陣列中返回。在客戶端,這是很簡單的修改使用remote datasource

$("#searchtxt").autocomplete({ 
     source: '@Url.Action("PopSearch", "ControllerName")' 
    }); 

更新:您可以coimbine像值:

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

你可以使用linq來組合它。也許這不是一個最好的解決方案,但我添加了樣本。 – Samich 2011-12-16 12:02:59