单个输入文本中的两个自动完成功能

发布于 2025-01-28 14:56:20 字数 1057 浏览 3 评论 0原文

我有两个自动完整功能,对于不同的文本框来说正常,我想在单个文本框中添加这两个自动完成功能值,
第一个功能:

$(function () {
$(".AccountSuplier").autocomplete({
    source: '/AccAddAcount/AutoSearchSupplierAcc'
});
});
//that I used with textbox like this :
<input asp-for="Supplier" class="form-control AccountSuplier">
           

第二个功能:

$(function () {
 $(".AutoEmplyee").autocomplete({
    source: '/EmpAddEmp/AutoSearchEmploy'
 });
 });

<input asp-for="Emplyee" class="form-control AutoEmplyee">

这两个功能正常工作,并给出不同文本框中的供应商和Emplyees的列表,现在我想在单个文本框中添加这些列表,

//在控制器中//代码in Controller :(对于供应商,就像雇员一样)

[HttpGet]
    public IActionResult AutoSearchEmploy()
    {
        var name = HttpContext.Request.Query["term"].ToString();

        PaginatedList<EmpAddEmploy> units = _EmpAddEmpRepo.GetItems("Name", SortOrder.Ascending, "", 1, 20);

        var data = units.Where(j => j.EmployeeName.ToLower().Contains(name.ToLower())).Select(j => j.EmployeeName);
        return Ok(data);
    }

I have two autocomplete function , that work fine for different textboxes , I want to add these two two autocomplete function values in single text box ,
1st function :

$(function () {
$(".AccountSuplier").autocomplete({
    source: '/AccAddAcount/AutoSearchSupplierAcc'
});
});
//that I used with textbox like this :
<input asp-for="Supplier" class="form-control AccountSuplier">
           

2nd function :

$(function () {
 $(".AutoEmplyee").autocomplete({
    source: '/EmpAddEmp/AutoSearchEmploy'
 });
 });

<input asp-for="Emplyee" class="form-control AutoEmplyee">

these two function work fine and give list of Supplier and Emplyees in different textboxes , Now I want to add these list in single textbox,

// code in controller for employ : (for Supplier is same like employ )

[HttpGet]
    public IActionResult AutoSearchEmploy()
    {
        var name = HttpContext.Request.Query["term"].ToString();

        PaginatedList<EmpAddEmploy> units = _EmpAddEmpRepo.GetItems("Name", SortOrder.Ascending, "", 1, 20);

        var data = units.Where(j => j.EmployeeName.ToLower().Contains(name.ToLower())).Select(j => j.EmployeeName);
        return Ok(data);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

謌踐踏愛綪 2025-02-04 14:56:20

您需要手动组合两个查询。没有测试,它看起来像这样:

$(function () {
    $(".SupplierEmployee").autocomplete({
        source: function (request, response) {
            let supplier = $.get("/AccAddAcount/AutoSearchSupplierAcc", {
                term: request.term
            });

            let employee = $.get("/EmpAddEmp/AutoSearchEmploy", {
                term: request.term
            });

            $.when(supplier, employee).done(function (data1, data2) {
                response(data1.concat(data2));
            });
        }
    });
});
<input asp-for="Supplier" class="form-control SupplierEmployee">        

You would need to manually combine the two queries. Without testing, it would look something like this:

$(function () {
    $(".SupplierEmployee").autocomplete({
        source: function (request, response) {
            let supplier = $.get("/AccAddAcount/AutoSearchSupplierAcc", {
                term: request.term
            });

            let employee = $.get("/EmpAddEmp/AutoSearchEmploy", {
                term: request.term
            });

            $.when(supplier, employee).done(function (data1, data2) {
                response(data1.concat(data2));
            });
        }
    });
});
<input asp-for="Supplier" class="form-control SupplierEmployee">        
萌无敌 2025-02-04 14:56:20

我尝试此尝试,但仅适用于一等班,并提供供应商的列表

<input asp-for="User" class="form-control AccountSuplier AutoEmplyee">

I try this but it work only for 1st class and give list of Supplier

<input asp-for="User" class="form-control AccountSuplier AutoEmplyee">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文