0
你好我有填充文本框的基礎上的搜索條件,即如果我鍵入一個然後項目開始於一個填充文本框中,我也用另一個文本框顯示partyname,但問題是當我選擇項目文本框中的值它不顯示在文本框中,但派對名稱文本框正在工作,即當我從下拉列表中選擇partyname它顯示在隱藏字段和文本框,但在項目的情況下它不工作即時發送我的jQuery功能,所以請幫助jquery-autocomplete-multiple-output
$(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);
};
}
ItemInfo類:
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();
}
您是否也可以提供您的HTML/ASPX代碼,並使問題描述更清晰一點? – tpeczek
爲什麼選擇事件沒有生成第二個文本框UI元素 – iProgrammer
那麼答案對你有幫助,你還有問題嗎? – tpeczek