ligerUI智能提示

function GetUser() {

       var cache = {};

       $("#user").autocomplete({

           minLength: 1,

            //查找数据源事件

           source: function (request, response) {

                var term =request.term.trim();

                //request.field = $('#city').attr("value");

                if (term in cache) {

                   response(cache[term]);

                    return;

               }

                $.getJSON('@Url.Action("GetUser")', request,function (data, status, xhr) {

                   cache[term] = data;

                   response(data);

               });

            },

            //选择项事件

           select: function (event, ui) {

                var item =ui.item;

               $('#hid_user').attr("value", item.id);//对隐藏的"hid_user" 赋上下拉列表的选中项的id

            }

        });

    }

 

 

 

[HttpGet]

public ActionResult GetUser()

{

JavaScriptSerializer jss = new JavaScriptSerializer();

ListSys_Operator>sys_operator_list = new ListSys_Operator>();

BLL.Sys_Operator bll_sys_operator = new BLL.Sys_Operator();

string strwhere = "";

string t = Request["term"];

strwhere = "[Name] like  '%" + t + "%'"; //生成搜索条件

     sys_operator_list = bll_sys_operator.GetModelList(strwhere);

     var cl = sys_operator_list.Select(c => new

      {

label = c.Name,

value = c.Name,

id = c.Id

}).Take(15);

return Json(cl, JsonRequestBehavior.AllowGet);

}

你可能感兴趣的:(ligerUI)