您好,我已经根据搜索条件填充了文本框,即如果我键入 a,那么以 a 开头的项目将填充在文本框中,并且我使用了另一个文本框,其中我显示了派对名称,但问题是当我在项目文本框中选择值时它不在文本框中显示,但派对名称文本框正在工作,即当我从下拉列表中选择派对名称时,它显示在隐藏字段和文本框中,但如果有项目,它不起作用,我正在发送我的 jquery 函数,所以请帮忙
$(document).ready(function() {
SearchText();
SearchItem();
});
function SearchText() {
$('input[name$="tbAuto"]').autocomplete({
source: function(request, response) {
$.ajax({
url: "PartyList.asmx/FetchPartyList",
data: "{ 'prefix': '" + request.term + "' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function(data) {
response(data.d);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
minLength: 1,
focus: function(event, ui) {
$('input[name$="tbAuto"]').val(ui.item.Name);
return false;
},
select: function(event, ui) {
$('input[name$="tbAuto"]').val(ui.item.Name);
$('input[name$="tbHidden"]').val(ui.item.value);
return false;
}
}).data('autocomplete')._renderItem = function(ul, item) {
return $('<li>').data('item.autocomplete', item).append('<a>' + item.Name + '</a>').appendTo(ul);
};
}
function SearchItem() {
$('input[name$="txtitem"]').autocomplete({
source: function(request, response) {
$.ajax({
url: "Itemslist.asmx/FetchItemList",
data: "{ 'prefix': '" + request.term + "' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function(data) {
response(data.d);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
minLength: 1,
focus: function(event, ui) {
$('input[name$="txtitem"]').val(ui.item1.Name);
return false;
},
select: function(event, ui) {
$('input[name$="txtitem"]').val(ui.item1.Name);
$('input[name$="hditem"]').val(ui.item1.value);
return false;
}
}).data('autocomplete')._renderItem = function(ul, item1) {
return $('<li>').data('item1.autocomplete', item1).append('<a>' + item1.Name + '</a>').appendTo(ul);
};
}
项目信息类:
public class Iteminfo
{
connection oConnection = new connection();
Control oControl = new Control();
AccountInfo oAccount = new AccountInfo();
connection c = new connection();
public string Title { get; set; }
public string Name { get; set; }
public string value { get; set; }
public List<Iteminfo> GetItems(string prefixText)
{
List<Iteminfo> itemList = new List<Iteminfo>();
try
{
DataTable dt;
AccountInfo oAccount = new AccountInfo();
//dt = oAccount.GetAccountInfo((int)HttpContext.Current.Session["CompCode"], 0);
dt = oAccount.GetIteminfo(prefixText);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
itemList.Add(new Iteminfo() { Name = dt.Rows[i]["groupname"].ToString() + dt.Rows[i]["subgroup"].ToString() + dt.Rows[i]["itemname"], Title = dt.Rows[i]["itemname"].ToString(),
value = dt.Rows[i]["groupname"].ToString() + dt.Rows[i]["subgroup"].ToString() + dt.Rows[i]["itemname"].ToString()+";"+dt.Rows[i]["itemcode"].ToString() });
}
}
}
catch (SqlException)
{
itemList.Add(new Iteminfo() { Name = "Problem Getting Results.", value = "Error" });
}
if (itemList.Count == 0)
itemList.Add(new Iteminfo() { Name = "Nothing to Display.", value = "Info" });
return itemList;
}
}
页面方式:
[WebMethod]
public List<Iteminfo> FetchItemList(string prefix)
{
var items = new Iteminfo();
var fetchitems = items.GetItems(prefix);
//.Where(m => m.Name.ToLower().StartsWith(prefix.ToLower()));
// .Where(m => m.Name.ToLower().StartsWith(prefix.ToLower()));
return fetchitems.ToList();
}