2

这是我执行 typeahead 的 js 代码:

jQuery.noConflict();
jQuery(document).ready(function(){
    jQuery('.search-field.input').typeahead({
        name: 'group-static',
        prefetch: 'http://ws.luyencong.net/data/search/query.php?do=advanced',
        header: '<span class="group-title">General Content</span>',
        template: [
        '<img class="icon" src="{{icon}}" style="width: 38px; height: 38px" />',
        '<div class="icon-desc"><span xmlns="http://www.w3.org/1999/xhtml" class="title">{{name}}</span>',
        '<span xmlns="http://www.w3.org/1999/xhtml" class="desc">{{description}}</span></div>',
        '<span class="clear"></span>'
        ].join(''),
        engine: Hogan
    });
});

Typeahead 被执行(因为我可以看到 tt-hint 输入,以及建议 div 的包装)但是有一个问题,当我输入一个字符时,建议没有按应有的方式显示。

我的 JSON 位于:http ://ws.luyancong.net/data/search/query.php?do=advanced

请给我一些帮助。谢谢。

4

1 回答 1

1

这不是真正的 typeahead.js 问题。luyencong.net问题是您正在从to发出跨域请求ws.luyencong.net。如果可以的话,托管预取 JSON 文件luyencong.net——这可能是最简单的解决方案。

jQuery('.search-field.input').typeahead({
  // ...
  prefetch: 'http://luyencong.net/data/search/query.php?do=advanced'
  // ...
});

如果你不能这样做,还有其他一些选择:

于 2013-07-19T22:08:18.817 回答