2017-08-02 26 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我使用它在我的项目

它是您可以用来实现自动完成功能的最佳软件包之一。