【发布时间】:2016-03-31 12:25:05
【问题描述】:
场景:我在前端有 AngularJS,在后端有 Django。我使用watson 在数据库中搜索产品。我正在尝试为“搜索”(input type="text")实现 autocomplete_light。
$('#searchText').yourlabsAutocomplete({
url: '{% url "get_search_results" %}', // this is where watson is getting used
choiceSelector: 'a',
minimumCharacters: 4,
}).input.bind('selectChoice', function(e, choice, autocomplete) {
window.location.href = choice.attr('href');
});
预期行为:上面的代码运行良好,并在我输入搜索文本字段时显示 product_json,但我希望它以完美呈现的 html 格式显示。我想知道如何在这里使用 AngularJS 来呈现这个 JSON 并根据选择提供href。
我发现下面的链接是 autocomplete.js
的文档http://django-autocomplete-light.readthedocs.org/en/stable-2.x.x/_static/autocomplete.html
【问题讨论】:
-
您似乎将 jQuery 与 Angular 混合在一起。这不是一个好的做法(它不会进入 Angular 摘要循环)。如果我理解正确,您可以使用 angular UI typeahead:angular-ui.github.io/bootstrap(在底部)
标签: javascript angularjs django autocomplete