jquery ui autocomplete ajax返回資料自訂顯示

來源:互聯網
上載者:User

標籤:des   blog   java   io   資料   cti   div   代碼   

1、body裡面的內容

<input type="text" class="inputTxt" id="txtJigou" autocomplete="off"/>

2、引入jquery.ui.min.js和他的樣式

3.js代碼如下<script type="text/javascript">

$(function(){$("#txtJigou").autocomplete({            source: function( request, response ) {                        $.ajax({                          url: "/Home/Organization/getList.html",                          dataType: "json",                          data: {                            "name": "中","typeid":"11"                          },                          success: function( data1 ) {                            if(data1.state==1){                                //data1返回json格式如下                                response(data1.data);                            }                          }                        });                    },            minLength:1,            autoFocus:true,            focus: function( event, ui ) {            $( "#txtJigou" ).val( ui.item.company );                return false;            },            select: function( event, ui ) {                $( "#txtJigou" ).val( ui.item.company );                return false;            }        }).autocomplete( "instance" )._renderItem = function( ul, item ) {
        //這裡是自訂顯示的資料,我需要顯示的資料是上面的data1.data return $( "<li>" ) .append( "<a>" + item.company + "<br>" + item.desc + "</a>" ) .appendTo( ul ); };});</script>

  

4、返回JSON的資料如下

   {    "state": 1,    "data": {        "10013": {            "id": "10013",            "company": "金穀信託",            "alias": "中國金穀國際信託有限責任公司"        },        "11031": {            "id": "11036",            "company": "民生信託",            "alias": "中國民生信託有限公司"        }    }}

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.