javascript - Select2 版本 4 及更高版本无法获取数据结果
问题描述
我有这个下面的javaScript,它在Select2版本低于 4 时运行良好,所以,现在我要将它升级到 4.0.7 版本,但它不起作用。你能指导我如何解决它吗?
$(".locations").select2({
minimumInputLength: 3,
width: '100%',
maximumSelectionSize: 1,
ajax:{
url: "My_URL_HERE",
dataType: 'json',
data: function(term) {
return { q:term }
},
results:function(data) {
return { results: data }
}
}
});
$(".locations").on("select2-selecting",function(e){
$("input[name=module_type]").val(e.object.module);
$("input[name=select2-search__field]").val(e.object.id);
$("input[name=slug]").val(e.object.id);
});
这是我的输入代码:
<input type="text" name="name" class="locations">
提前致谢
解决方案
推荐阅读
- c++ - 在某个命名空间中定义方法时在全局命名空间中声明?
- sql - 获取嵌套 JSON 列的值
- r - 如何解析和提取凌乱的 Excel 数据?
- python - cv2.cornerHarris 返回什么?
- arduino - 使用 Arduino Mega 作为 I2C 从设备和 RPi3
- apache - Apache Storm 应用程序的部署异常
- javascript - LEFT OUTER JOIN 查询结果的Javascript转换
- php - 保护图片和pdf用户,查看文件只有用户登录
- javascript - 如果第一个日期时间大于第二个日期时间,则为 Javascript
- magento - Magento 2 - 显示正常价格、特价和折扣