繁体   English   中英

使用键盘选择时如何在输入框中显示产品名称

[英]How could I show product name in the input box when selecting with keyboard

先前的成员编写了用于自动完成搜索的Angular js。

当我输入一些关键字时,它将返回我的候选者。

但是,当我用箭头键导航这些候选人时,它将在输入框中显示product id ,我想显示product name

我怎么用angular js做到呢?

item.label是产品名称,而item.value是产品ID

我不熟悉,非常感谢

js

$(document).ready(function(){
    $("#search_bar").autocomplete({
        source: function (request, response) {
                 console.log(request['term']);
                 name = "name="+request['term'];
                 $.ajax({
                     url: "/v1/search/",
                     type: "GET",
                     data: name,
                     success: function (data) {
                        console.log(data);
                         response($.map(data, function (el) {
                             return {
                                 label: el.name,
                                 value: el.id
                             };
                         }));
                     }
                 });
            },
        focus: function (event, ui) {
            $("#search_bar").val(ui.item.label);
        },
        select: function (event, ui) {
            $("#search_bar").val(ui.item.label);
            $("#search_bar_id").val(ui.item.value);
            window.location.href = '/browse/'+ui.item.value;
            return false;
        }
    });
});

angular-ui的预输入效果很好! 您可以使用此: https : //github.com/angular-ui/bootstrap/tree/master/src/typeahead

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM