0

当我的 jQuery 自动完成功能获取 json 数据项时,如何获取所选项目并将它们分配给我的 DOM 中的其他文本框?

我是否在文本框中连接了一个事件?

我的js:

$(document).ready(function () {
$("#CustByName").autocomplete(
    {
        source: function (request, response) {
            $.ajax(
            {
                url: "/Cases/FindByName", type: "GET", dataType: "json",
                data: { searchText: request.term, maxResults: 10 },
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    response($.map(data, function (item) {
                        return {
                            label: item.CustomerName,
                            value: item.CustomerName,
                            id: item.CustomerID
                        }
                    })
                    );
                }
            });
        },
        minLength: 3
    });

});

和我的控制器动作:

//Post: autocomplete customer names
    //[HttpPost]
    public JsonResult FindByName(string searchText, int maxResults)
        {
        CustomerFind find = new CustomerFind();
        var result = find.FindCustomerByName(searchText, maxResults);
        return Json(result, JsonRequestBehavior.AllowGet);
        }

和我的 FindCustomerByName 函数

internal List<Models.Customer> FindCustomerByName(string searchText, int maxResults)
        {
        List<Models.Customer> result;

        using (cummins_sqldb dataContext = new cummins_sqldb())
            {

            result = (from c in dataContext.Customers
                      where c.CustomerName.Contains(searchText)
                      orderby c.CustomerName
                      select c).Take(maxResults).ToList();
            }
        return result;

        }
4

0 回答 0