使用場景:
A頁面以及B頁面,A頁面有個下拉框,數據是從B頁面存在的數據庫中獲取得到的;現將B頁面的數據刪除掉,但是在A頁面再次點開下拉框時,依舊看到了剛才刪除的那條數據;
期望:當B頁面已何種方式改變數據庫的值時,A頁面的下拉框均能實時刷新。
起初不能實現的方法:
1 <td align="right">分類:</td> 2 <td align="right"><input id="s_typeid" 3 data-options="valueField:'typeid',textField:'typename',panelHeight:'150px';url:'/hotspot/questionstype/typelist'" 4 style="width: 150px;" class="easyui-combobox"></td>
1 <script> 2 $(function(){ 3 $('#s_typeid').combobox({ 4 url:'/hotspot/questionstype/typelist?t=' + new Date().getTime(), 5 valueField:'typeid', 6 textField:'typename' 7 }); 8 </script>
直接在頁面加載完成后,就將下拉框的數據獲取到,並賦值給它,於是就出現文章開頭的那個問題,后來解決辦法:
將HTML中的url屬性(第一段代碼的綠色部分)去掉,然后使用combobox的onShowPanel方法便可:
1 $('#s_typeid').combobox({ 2 onShowPanel : function(){ 3 var s=$(this).combobox('getData'); 4 $(this).combobox('options').url= '/hotspot/questionstype/typelist?t=' + new Date().getTime(); 5 $(this).combobox('reload'); 6 } 7 });