jquery-ui-autocomplete를 사용하여 자동 완성 기능이있는 텍스트 상자를 개발하고 있습니다. 그리고 원하는대로 기능을 수행하는 데 문제가 있습니다. 시작하려면 필자는 컬럼 값 중 일부가 생략 된 회사 테이블을 가지고 있습니다.) A.B.C. 이 자동 완성 기능을 사용하면 원하는 기능을 제외한 모든 기능을 사용할 수 있습니다. 입력 할 때 abc corp 또는 ABC corp는 A.B.C와 일치합니다. Corp,하지만 그렇지 않습니다. (abc corp를 입력하면 일치합니다 : 내 코드는 여기에 있습니다. 그리고 그것에 대해 어떻게할지는 모르겠습니다. 올바른 방향으로 팁을 보내 주시면 감사하겠습니다. ? 내가 어떻게 ABC 공사 ABC 공사에 내 현재의 방법은 작동하지 않습니다자동 완성 정규 표현식 필터링
Regex.Match(hint, "/([A-Za-z\\.])/g"
감사와 일치 할 수 클라이언트 측 :
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<link href="Content/themes/base/all.css" rel="stylesheet" />
<script src="Scripts/jquery-1.10.2.min.js"></script>
<script src="Scripts/jquery-ui-1.11.4.min.js"></script>
<asp:TextBox runat="server" ID="customerSearch"></asp:TextBox>
<script type="text/javascript">
$(document).ready(function() {
$("#MainContent_customerSearch").autocomplete({
source: function (request, response) {
$("#MainContent_customerSearch").on("change keyup", function() {
var hint = { hint: $("#MainContent_customerSearch").val() };
//call webmethod
$.ajax({
type: "POST",
url: "Default.aspx/getProducts",
data: JSON.stringify(hint),
dataType: "json",
contentType: "application/json; charset=utf-8",
}).success(function (data) {
response($.map(data.d, function (item) {
return {
label: item.Description,
value: item.Description
}
}));
}).error(function (error) {
console.log(error);
});
});
},
delay: 0,
minLength: 1,
autoFocus: true
});
});
</script>
</asp:Content>
서버 측 :
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static List<Product> getProducts(string hint)
{
List<Product> products = new List<Product>();
using (var db = new AppDB())
{
try
{
products = db.Products.Where(p => p.Description.Contains(hint)).ToList();
}
catch
{ }
}
return products;
}
}