2017-08-02 28 views
-1

嗨和謝謝你幫助我,英語不是我的第一語言,提前抱歉。 :)如何使用Symfony3 AJAX和Chosen2自動完成

當選擇選擇框時,我得到通知「找不到結果」,但是當我在開發人員工具欄中查看結果時,發現我收到了完整的JSON。

如何匹配單個值而不是獲取整個JSON?

JSON結果:

["Descent: Journeys in the Dark (Second Edition)","Dominion","Ascension","Star wars LCG","Magic: The 
Gathering Duel Decks Anthology"] 

腳本:

<script type="text/javascript"> 
    $('select').select2({ 
     placeholder: 'Select an item', 
     ajax: { 
      url: '{{ path('user_games_json') }}', //url to the json data 
      dataType: 'json', 
      delay: 250, 
      processResults: function (data) { 
       return { 
        results: data 
       }; 
      }, 
      cache: true 
     } 
    }); 
</script> 

回答

0
,如果你想通過Ajax請求從服務器的數據可以使用 Select2 Bundle我使用它在我的項目

它是您可以用來實現自動完成功能的最佳軟件包之一。