简体   繁体   English

自动完成:我如何像 facebook 一样使用自动完成?

[英]Autocomplete: How can I use autocomplete like facebook?

I have already tried textcomplete, But I really face a problem that I can only set single value on select.我已经尝试过 textcomplete,但我真的面临一个问题,我只能在选择上设置单个值。

In autocomplete I know how to set multi values.在自动完成中,我知道如何设置多值。 But don't know how could i convert it as shown in picture below ...但不知道如何转换它,如下图所示......

在此处输入图片说明

You can also look back what i have tried in textcomplete here - Text Complete Query您还可以在这里回顾我在 textcomplete 中尝试过的内容 - Text Complete Query

Firstly you need to include auto complete js and css.首先,您需要包含自动完成的 js 和 css。

HERE is the link https://blog.jqueryui.com/2015/03/jquery-ui-1-11-4/这里是链接https://blog.jqueryui.com/2015/03/jquery-ui-1-11-4/

Include jquery-ui js and jquery-ui css包括 jquery-ui js 和 jquery-ui css

$("#txtSeller").on('keyup', function(e){
var currentObj = $(this);
jQuery("#txtSeller").autocomplete({
    source: function(request, response) {
        var postData = {
            "operation":"search",
            "sellerName": currentObj.val()//sending the name to backend
        }

        $.ajax({
            type: "POST",
            cache: false,
            url: "controllers/admin/put_orders.php",
            datatype:"json",
            data: postData,

            success: function(dataSet) {
                response($.map(JSON.parse(dataSet), function (item) {
                    return {
                        id: item.id,
                        value: item.name
                    }
                }));
            },
            error: function(){

            }
        });
    },
    select: function (e, i) {
        var sellerId = i.item.id;
        currentObj.attr("seller-id", sellerId);
        $("#txtSeller").val(i.item.value);
    },
    minLength: 3
});

}); });

HERE is the complete code for autocomplete.这里是自动完成的完整代码。

Please make you write the sql query for this ajax call don't forgot to write LIKE parameter in Sql Query请让您为此ajax调用编写sql查询不要忘记在Sql Query中编写LIKE参数

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

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