drvvvuyia15070493 2016-12-04 15:43
浏览 42
已采纳

如何在symfony 3中使用twitter / tyepahead.js和blodhound实现自动完成功能

I have an ajax route which respond a json array with sites which gets it from a txt file. In my twig template Im using typeahead function to do an ajax call like:

var sites= new Bloodhound({
  datumTokenizer: Bloodhound.tokenizers.whitespace,
  queryTokenizer: Bloodhound.tokenizers.whitespace,

  remote: '{{'ajax_fun'}}'
});


$('#bloodhound .typeahead').typeahead({
  name: 'sites',
  source: sites
});

The filtering on input field does not work even thought i get the array with the sites.

  • 写回答

1条回答 默认 最新

  • drblhw5731 2016-12-04 22:10
    关注

    In case someone want to know how to populate states with json array getting from remote path this was my solution:

    var states = [];
    var statesBloodhound = new Bloodhound({
      datumTokenizer: Bloodhound.tokenizers.whitespace,
      queryTokenizer: Bloodhound.tokenizers.whitespace,
      // `states` is an array of state names defined in "The Basics"
      local: states
    });
    
    //populate the statesBloodhound 
    $.getJSON('path', {
    }).done(function(data){
       statesBloodhound.add(data); 
    })
    
    $('#bloodhound .typeahead').typeahead({
      name: 'statesBloodhound ',
      source: statesBloodhound 
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)