从列表json中选择多个 [英] select2 multiple from list json

查看:175
本文介绍了从列表json中选择多个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从列表中加载select2的选项。

这是我到目前为止所做的:

查看

- ---

I am trying to load options for select2 from a list.
Here is what I have done so far:
View
----

<input type="hidden" id="myInput" multiple="multiple" />





Js文件

-------



Js file
-------

$("#myInput").select2({
  placeholder: "select from the following",
  ajax:
  {
     url:http://debug:10482/myData/GetList",
     dataType: "jsonp",
     data: function (term, page) {
       return {
        q: term,
        page_limit: 10,
        apikey: "ju6z9mjyajq2djue3gbvv26t"
       };
     },
     results: function (data, page) {
       return { results: data}
     }
  }
});





myData.cs

---------



myData.cs
---------

public jsonResult GetList(string q)
{
   List<string> myList = new List<string>() {"one, "two", "three"};
   return Json(myList);
}





我可以在调试中看到它进入GetList功能但是看不到任何

结果在select2输入中找到。



I can see in debug it enters the "GetList" function but can''t see any
results found in the select2 input.

推荐答案

(#myInput)。select2({
占位符:从以下选择,
ajax:
{
url:http:// debug:10482 / myData / GetList,
dataType:jsonp,
data:function( term,page){
return {
q:term,
page_limit:10,
apikey:ju6z9mjyajq2djue3gbvv26t
};
},
结果:函数(数据,页面){
返回{结果:数据}
}
}
});
("#myInput").select2({ placeholder: "select from the following", ajax: { url:http://debug:10482/myData/GetList", dataType: "jsonp", data: function (term, page) { return { q: term, page_limit: 10, apikey: "ju6z9mjyajq2djue3gbvv26t" }; }, results: function (data, page) { return { results: data} } } });





myData.cs

---------



myData.cs
---------

public jsonResult GetList(string q)
{
   List<string> myList = new List<string>() {"one, "two", "three"};
   return Json(myList);
}





我可以在调试中看到它进入GetList功能但是看不到任何

结果在select2输入中找到。



I can see in debug it enters the "GetList" function but can''t see any
results found in the select2 input.


这篇关于从列表json中选择多个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆