首先学习这个东西呢,还是看官网比较全面
要select2中文显示:必须要引入中文包,且一定要放在select2.js之后
- <link type="text/css" rel="stylesheet" href="/css/select2.css">
- <script type="text/javascript" src="/js/select2.full.min.js"></script>
- <script type="text/javascript" src="/js/i18n/zh-CN.js"></script></span>
- $(".selectProduct").select2({
- ajax:
- {
- url: "getProducts",
- dataType: 'json',
- type: 'POST',
- delay: 250,
- data: function (params)
- {
- var param = new Object();
- param.name = params.term;
- return param;
- },
- processResults: function (resp, page)
- {
- var array = new Array();
- if (resp.products)
- {
- for (var i = 0; i < resp.products.length; i++)
- {
- var product = resp.products[i];
- array.push({id:product.productId, text: product.productName});
- }
- }
- var ret = new Object();
- ret.results = array;
- return ret;
- },
- cache: true
- },
- minimumInputLength: 2,
- language: "zh-CN",
- }); </span>