我正在使用 Select2 JS 版本 4.0.0-rc.1,并且在使用远程 Ajax 方法加载建议时遇到问题。
以下是标记和代码
<select class="form-control input-sm" id="selFrame1" name="selFrame1">
<option> Select Frame </option>
</select>
JavaScript Jquery
$('#selFrame1').select2({
ajax: {
url: siteUrl+"suggest/frames",
dataType: 'json',
delay: 250,
method:'POST',
data: function (params) {
return {
q: params.term, // search term
page: params.page
};
},
processResults: function (data, page) {
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
return {
results: data.result
};
},
cache: true
}
});
服务器返回的Json结果
{results: [{"Code":"123360000"},{"Code":"123360358"},{"Code":"123364000"},{"Code":"123400000"}], more: false }
我完全不确定是否需要编写特定的函数来显示建议,Ajax 部分的评论说我们不应该更改结果 Json 数据。
现在请有人告诉我还应该做什么才能让代码正常工作以显示建议。
我想新版本的 select2 改变了很多东西。