jquery-ui autocomplete 自动完成功能

时间:2023-12-05 15:37:56

效果图

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAh8AAACCCAIAAABpWD0yAAAQg0lEQVR4nO2dXVMbybmA9Ud8w/X+inPt+4STVMEvyOYsWa/xfmRXWUNyc6pOgiunyldLLmyDMKxBuOyLU7VObG+tA1k+ZCzs47CmAAtkPmILkAV0LjQatWa6RyPNiOkZPW89RY16enpGmrffR6MBlKocHQEAAIRLKvIjAACA5IFdAAAgfLALAACED3YBAIDwwS4AABA+2AUAAMIHuwAAQPhgFwAACB/sAgAA4YNdAAAgfLALAACED3YBAIDwwS4AABA+XW2X0st7e48+hbhTenkv8lwCAAfda5fSy3u56x88/ubnEHdy1z9AMG7GJ6YhGUSeS+3RvXbZe/Tp429+Loj4x+NvevceXYk8o0xjfGI66jNDhBD+7ZKJKHTHo7ZLKpVSLicJ7JKYwC5KsEsyoiW77J97tGYXt058CialCe+1ys5NxwzuPD92SaVS55NARJDwY5c2ci/W6Y1dEhMt2WXv3KMFu+jSuqV0V3Z2NPrpE9bxKMEuiYng1y7JS+8KdklKJMQu3jmdavy4TPdWy+eEiXz6YZfEREC7+LmkiF16V7BLUqIlu+z6iFQq1bRd18cdvuzikdD2Ku/p4X2B70dO0dhl68bPnIfzsxtbQmCXmEQQuwR5R2VyelewS1IiuF2UqSuHWyre3Vq2i0dme+S6boJ5rPWelu4RdBFw7jXaZfixfD4fD1cFk8IucYj27OIni+Kb3hXskpRoyS5vPCOVSjl+enTz0/jmzZvztot7wV52rHKMHMqk8omXXWpN2CUW0bZdWuoTr/SuYJekREt2KeojlUrpFtzdHO91dJ2LxWIHfyO51ennPdkcbwB9RntzD7skJprape10im96V7BLUiK4XaqJ5NaMY5Vj2e2beNjFnjaO+aPcV5AJ5kGzT8aGH3PfJSZhzrWLOeldwS5JiZbssqMP5XsXdx/Hgr3s7lyNlu1iJ33T1G9p+unejnmv8j+dWnqvx139xIQhdjEqvSvYJSnRkl229ZFKpfy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382MX7b/Ub/g0Md/U7DHYBMBDsoqhWvuwiRJP/M9agH/4NTAfBLgAGgl2iL44QEOwCYCDYJfriCAHBLgAGgl2iL44QEOwCYCDYJfriCAHBLgAGgl2iL44QEOwCYCDYJfriCAHBLgAGgl2iL44QEOwCYCDYJfriCAHBLgAG0tV26c+8erFbjrw4QhBe7JZ/M7sReS4BgIOutsveQWkgu3FxdA3iy0B2Y++gFHkuAYCDrrYLAAB0COwCAADhg10AACB8sAsAAIQPdgEAgPDBLgAAED7/Bjs1ooc7TFN4AAAAAElFTkSuQmCC" alt="" />

如果想给每个文本框都加上自动完成功能该怎么办呢?一个一个添加太麻烦。可以给文本框设置一个属性,让这个属性的值等于Controller里的action。就像这样:

父项图号:<input id="pn" name="pn" type="text" data-autocomplete="@Url.Action("QuickSearch","BOM")"/>
子项图号:<input id="cn" name="cn" type="text" data-autocomplete="@Url.Action("QuickSearch","BOM")"/>
$(document).ready(function () {
$(":input[data-autocomplete]").each(function () {
$(this).autocomplete({ source: $(this).attr("data-autocomplete"),autoFocus:true });
});
});

QuickSearch方法如后。

jqGrid的搜索框还是单独做吧。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAd0AAAC8CAIAAACygONyAAAVVElEQVR4nO2d23MU152A9Y/woueU/wg/7JMe8uYoiYt5ySNmDbYxRviiJNZuXraSQHm3XOUqK9RKRiOQkZBI1dY6S4JJ4YXFSEIXIBYSktBIgADrhuayDz3T6ulz6dM9031mur9ffeXqPn369Ln1p+NmZrpj/sHDY2OPuvoXAADALscuL99bXOk4NvZofmOnWCoBAIBd5jd2jl1e7ujqX7BeFQAAcOjqXzjw8qNnO7mB+69/NgMAAImRG7j/6NmO3Mu5gfunRub/dQIAAJLj1Mh8buC+3MuvfzZjvX4AABnk9c9mlF7+l4l5AABIGLwMANBa4GUAgNYiwMt94/N94/POhuq/3l3NKd4M7uXFc72HXHyVDixBPNdXiFhJ8dKa1qmqJJYj7XRfxVSXVjVQ2nx9fnFEpKOpQtN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b5VZmeXP//8ze/g2hwBH0ebuQMlMFeHm3WLq9uHnt3kYrc3txc7dYsj4z0geOoM/bhZSZKsDLkGWYGPQ5WAEvgxImBn0OcbO+tf9Pnz/wJeJlUJLLL95/ume9Gtnh/tO9dyZWrFcDEsOR8vrWvi8dL4OSF3ul4+MrXf0LkAzHx1de7PEvJVnBlTLrZQAA+3ilzHoZAMAyPimzXgYAsEmglMt4GQAgSQKlXMbLAACtBl4GAGgt8DIAQGuBlwEAWouu/oWOw+cX+FoXAEArcP/p3tujix3zDx4evbRo/ctOAABw9NLi/IOHHUsLCwAA0Dr8PxQJe1NgHYvwAAAAAElFTkSuQmCC" alt="" />

View

在colModel中给字段加上一个dataInit事件。这样在编辑和查找时都会有自动提示了。

 colModel: [
{
name: 'PNumber', width: 40, index: 'PNumber',
editable: true, editrules: { required: true },editoptions:{dataInit:numberAuto},
searchoptions: {dataInit:numberAuto, sopt: ['eq', 'cn'] }
},
{
name: 'CNumber', width: 40, index: 'CNumber',
editable: true, editrules: { required: true }, editoptions: { dataInit: numberAuto },
searchoptions: {dataInit:numberAuto, sopt: ['eq', 'cn'] }
}
]
function numberAuto(e) {
$(e).autocomplete({source:'/BOM/QuickSearch',autoFocus:true,delay:100});
}

Controller:

通过Union查询操作符将2个字段合并(自动去除重复项),然后取出前10条数据。这个action传递给autocomplete里的source属性:autocomplete({source:'/BOM/QuickSearch',autoFocus:true,delay:100})。

     public ActionResult QuickSearch(string term)
{
var q =
(
from p in db.BOM
where p.PNumber.Contains(term)
select p.PNumber
)
.Union
(
from c in db.BOM
where c.CNumber.Contains(term)
select c.CNumber
)
.Take();
return Json(q, JsonRequestBehavior.AllowGet);
}

--END--