使用 ASp.Net Web 服务进行 JQuery 自动完成
我正在使用 ASP.Net Web 服务开发 JQuery 自动完成功能。 我在 JQuery (JSON) 下拉列表中调用 ASP.Net Web 服务,
$(document).ready(function () {
$("#txtTest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Webservice.asmx/GetNames",
data: "{'prefix':'" + request.term + "'}",
dataType: "json",
async: true,
success: function (data){
response($.map(data, function(item)
{ return item ; }));
},
error: function (result) {
alert("Due to unexpected errors we were unable to load data");
}
});
},
minLength:2
});
});
并且我在自动完成下拉列表中获取输出,如
{"First":"Steve","Second":"AK"}
{"First":"Evet","Second":"EV"}
{"First":"Stevens","Second":"SV"}
如何单独显示“第一个”项目(如 Steve、Evet、Stevens)作为下拉自动完成的输出?
请帮我!
I am working on the JQuery Autocomplete using ASP.Net webservice.
I have ASP.Net webservice being called in JQuery (JSON) drop down as
$(document).ready(function () {
$("#txtTest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Webservice.asmx/GetNames",
data: "{'prefix':'" + request.term + "'}",
dataType: "json",
async: true,
success: function (data){
response($.map(data, function(item)
{ return item ; }));
},
error: function (result) {
alert("Due to unexpected errors we were unable to load data");
}
});
},
minLength:2
});
});
And i am getting the output on the drop of auto-complete as
{"First":"Steve","Second":"AK"}
{"First":"Evet","Second":"EV"}
{"First":"Stevens","Second":"SV"}
How do i display the "First" items alone (Like Steve, Evet, Stevens) as the output of the drop down auto-complete?
Please help me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要查看 AutoComplete 方法上的 formatItem 选项 - 试试这个
You need to look at the formatItem option on the AutoComplete method - try this
这可能会成功
this would probably do the trick
看看我对此的回答: Jquery Autocomplete 2 Fields
但使用您的值而不是字段中的“A”和“B”。
此外,您(可能)需要一个转换器来处理 asp.net 数据:
Take a look at my answer to this one: Jquery Autocomplete 2 Fields
but use your values instead of "A" and "B" in the fields.
In addition, you (might) need a converter to handle the asp.net data: