[JQuery] 解決Select2 輸入文字搜尋時令瀏覽器不能運作

Select2.js 是JQuery 一個套件, 既整合了dropdown 亦加入了AutoComplete 的功能. 然而若根據文件去使用時, onChange() 卻有機會令瀏覽器不能運作.Google 了後發現是Select2.js Render 時出現問題, 但在現在(11-Apr-2018), 問題仍未解決, 那唯有利用work-around 處理.

方法就是自行於select 中加入option, 方法如下:

$("#dropDown").select2();
	  $.getJSON( "<<Test URL>>", function( data ) {    
		    $.each(data, function(i , d){
		    	$('#dropDown').append('<option value="' + d.code + '">' + d.name + '</option>');
		    });
	  });

參考資料

About C.H. Ling 262 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.