select2의 기본 응용

2194 단어 select2
AJAX:
반환된 json
{"staffs":[{"id":"
[email protected]","name":"С°ÝÄê","email":"
[email protected]"},{"id":"
[email protected]","name":"Сӣ","email":"[email protected]"}]}
------
JSP 코드:
<link href="<%=path%>/css/select2.css" rel="stylesheet" />
<script type="text/javascript" src="<%=path%>/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/select2.js"></script>


<script type="text/javascript">
// ÒÔÏÂΪselect2
    function movieFormatResult(staff) {
        return staff.name + ":" + staff.email+";";
    }
    function movieFormatSelection(staff,container) {
        return staff.name + ":" + staff.email+";";
    }
 
    $(document).ready(function() {
        $("#staffId").select2({
        	 tags:[],
             tokenSeparators: [",", " "],
             multiple:true,
        	allowClear: true,
            placeholder: "ËÑË÷ÐÕÃû",
            minimumInputLength: 2,
            ajax: {
            	type:"post",
			    url: "<%=path%>/hr/manager!searchEmail.do?status=1,2,3",
				dataType : 'json',
				quietMillis : 500,
				 
				data : function(term, page) {
					return {
						c : term, // Óû§ÊäÈëµÄ×Ö·û´® getParameter("q")
						page_limit : 10,
						apikey : "NoUse" // jspÒ³ÃæÖÐgetParameter("apikey")¿ÉÒԵõ½ 
					};
				},
				results : function(data,page) {
					return {
						results : data.staffs
					};
					
				}
			},
            createSearchChoice: function (term, staff) {
                t=term;
        	    if (t!==""&&staff.indexOf(t)<0) {
        	    	staff.push({id:t,name:t, email:t});
        	    }
            },
			formatResult : movieFormatResult,
			formatSelection : movieFormatSelection
		});
	});
</script>

참조 사이트 주소:http://jsfiddle.net/ivaynberg/seck4/10/
http://jsfiddle.net/XcG7n/8/
http://jsfiddle.net/5HZB3/

좋은 웹페이지 즐겨찾기