在select2上禁用ajax缓存的正确方法是什么?
问题描述:
我使用select2将远程数据加载到html选择在select2上禁用ajax缓存的正确方法是什么?
问题是,如果用户选择一个选项 - >清除输入 - >数据更改服务器 - >用户再次搜索数据。如果我要求选择的数据,它会返回旧的(以前选择的)值。
例子:
//User search for an option and selects it
$('#someSelect').select2('data').Limit
//Here the limit is 0
//Server data changes on server. Now limit is 10
//User searchs again for the same option and selects it
$('#someSelect').select2('data').Limit
//The value returned in the line above is 0 again
//Somehow the data previously selected is cached
//and returned instead of the refreshed data
设置缓存:假的不会做任何事情。
答
几小时后,我想出了解决方案。
关于事件select2:取消选择我必须清除选择的所有选项,因为插件已将选定选项添加到DOM。
$('#someSelect').on('select2:unselect',function(){
$('#someSelect').html(null);
});
对不起,听不懂你的问题。 –
对不起,英语不是我的第一语言,所以我必须努力一点,才能让我明白。 –