像标题中描述的那样,我得到了让jqueryUI自动完成Widget工作的一个小问题。asp.NET jqueryUI自动完成
这听起来很愚蠢,但我m hanging the whole day getting that thing solved, but i didn
吨。我已经开发了几年C#,现在正在努力,因为一个月左右...,用asp和jquery开发。为了显示,我搜索了网页,特别是stackoverflow,并试图让它运行。
确定这里的代码。
定义文本框:
<asp:TextBox ID="txtSearchbox"
style="float:left;padding:5px 1px 5px 1px;" runat="server" >
</asp:TextBox>
自动完成jQuery脚本部分:
<script type="text/javascript">
$(document).ready(function() {
$('#txtSearchbox').autocomplete({
source: function (request, response) {
//console.log(request.term);
$.ajax
({
url: "AutoComplete.asmx/GetSearchInfo",
data: "{ 'prefixText': '" + request.term + "' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) {
//console.log(data.toString());
//alert(data.toString());
return data;
},
success: function (data) {
// console.log(data.d.toString());
response($.map(data.d, function (item) {
// console.log(item.Isin)
// console.log(item.Name)
return
{
label: item.Name.toString()
value: item.Name.toString()
}
}));
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
minLength: 2
});
});
</script>
的AutoComplet.asmx:
[WebMethod]
public List<SearchObject> GetSearchInfo(string prefixText)
{
var seo = new SearchObject();
var getSeo = staticList.getSEOlist().Where(str => str.SearchString.ToLower().Contains(prefixText.ToLower()));
return getSeo.ToList();
}
为了完整起见,CSS:
/*AutoComplete flyout */
.autocomplete_completionListElement
{
margin:0px!important;
background-color:#ffffff;
color:windowtext;
border:buttonshadow;
border-width:1px;
border-style:solid;
cursor:'default';
overflow:auto;
height:200px;
font-family:Tahoma;
font-size:small;
text-align:left;
list-style-type:none;
padding: 5px 5px 5px 5px;
}
/* AutoComplete highlighted item */
.autocomplete_highlightedListItem
{
background-color:#ffff99 ;
color:black;
padding:0px;
}
/* AutoComplete item */
.autocomplete_listItem
{
background-color:window;
color:windowtext;
padding:0px;
}
如果你需要更多的,请告诉我。
调试行被注释掉。
如果我检查jquery部分我得到我想要的数据,但它不会显示在txtsearch。 我真的不明白自动完成jquerUI方法如何显示该列表,但编码应该是正确的。
什么是从你的Web服务方法的响应是什么样子? (如发送给客户端的JSON编码数据) –
{“d”:[{“__ type”:“SearchObject”,“Nr1”:“58155”,“nr2”:“E58155”,“Name”: “XX Name”,“SearchString”:“58155 XX Name E58155”}]} - 但没关系,它是一个JavaScript特性 - 查看最后一个答案,将代码结构稍微改变一点,一切正常,真的有线。 –