weixin_33733810 2013-10-16 13:10 采纳率: 0%
浏览 24

Typeahead.js出现问题

I have been trying to use typeahead.js on my project. I need data from my mysql database. But there have been no suggestions whatsoever. I have almost tried everything. Here is my code:

The HTML file:

    <html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <script src="js/typeahead.js"></script>
</head>
<body>

<div class="ui-widget">
  <label for="tags">Companies: </label>
  <input id="tags"/>
</div>

 <script>
$('#tags').typeahead({                                
  name: 'tags',                                                          
  prefetch: 'file.json'                                                            
});
</script>
</body>
</html>

file.json

    [ 
{ 
    "value": "Maini Optics",
    "tokens": ["Maini","Optics"]
},
{
    "value": "Prakash Eyewear",
    "tokens": ["Prakash","Eyewear"]
},
{
    "value": "Eternity Lifestyles",
    "tokens": ["Eternity","Lifestyles"]
},
{
    "value": "Aeurole Inspecs",
    "tokens": ["Aeurole","Inspecs"]
},
{
    "value": "Dynamic Eyewear",
    "tokens": ["Dynamic","Eyewear"]
},
{
    "value": "abc",
    "tokens": ["abc"]
},
{
    "value": "Test",
    "tokens": ["Test"]
}
]

Please help...

  • 写回答

2条回答 默认 最新

  • 撒拉嘿哟木头 2013-10-16 13:21
    关注

    PHP (single values in the array, i.e: $values = array('Maini Optics', 'Prakash Eyewear') ):

    $typeahead_data = implode("','", $values);
    

    HTML:

    <input type="text" name="name" id="name_typeahead" autocomplete="off" />
    <button type="submit" class="btn btn-primary"><i class="icon-search icon-white"></i>&nbsp;Search</button>
    

    JS

    $("#name_typeahead").typeahead({
        source: ['<?=$typeahead_data;?>'],
        items: 20
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作