2017-06-05 91 views
1

我使用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 

設置緩存:假的不會做任何事情。

+0

對不起,聽不懂你的問題。 –

+0

對不起,英語不是我的第一語言,所以我必須努力一點,才能讓我明白。 –

回答

1

幾小時後,我想出瞭解決方案。

關於事件select2:取消選擇我必須清除選擇的所有選項,因爲插件已將選定選項添加到DOM。

$('#someSelect').on('select2:unselect',function(){ 
    $('#someSelect').html(null); 
}); 
1

您也可以reset的選擇2下拉以清除選項..

$('#someSelect').select2("val", "All"); 
相關問題