【发布时间】:2010-11-06 18:37:04
【问题描述】:
下午好
我遇到了麻烦,试图弄清楚如何使用这个autocomplete plugin 并让它使用我的 WCF 服务方法。 WCF 已正确发布并正常工作。
可以做些什么来自动完成插件工作,或者是否有另一种聪明的方法可以使自动完成与 WCF 一起工作并获得选择的 Person.Id 和 Person.Name?
下面是我现在一直在做的一些事情:
WCF 服务
public class Person {
public int Id {get;set;}
public string Name {get;set;}
public static List<Person> List(){
/*long query supressed to no be annoying :) */
}
}
[ServiceContract]
public interface IChatService
{
[OperationContract]
[WebInvoke(Method = "GET",
UriTemplate = "GetPeople",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Json)]
List<Person> GetPeople();
}
public class MyService : IMyService
{
public List<Person> GetPeople()
{
return Person.List();
}
}
现在是aspx页面:
....
<head>
<script type="text/javascript" src="http://view.jquery.com/trunk/plugins/autocomplete/lib/jquery.js"></script>
<script type='text/javascript' src='http://view.jquery.com/trunk/plugins/autocomplete/lib/jquery.bgiframe.min.js'></script>
<script type='text/javascript' src='http://view.jquery.com/trunk/plugins/autocomplete/lib/jquery.ajaxQueue.js'></script>
<script type='text/javascript' src='http://view.jquery.com/trunk/plugins/autocomplete/lib/thickbox-compressed.js'></script>
<script type='text/javascript' src='http://view.jquery.com/trunk/plugins/jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="http://view.jquery.com/trunk/plugins/jquery.autocomplete.css" />
<link rel="stylesheet" type="text/css" href="http://view.jquery.com/trunk/plugins/lib/thickbox.css" />
<script>
$().ready(function () {
$('#<%=peopleNames.ClientID%>').autocomplete("http://localhost/MyService/MyService.svc/GetPeople", {
width: 260,
selectFirst: false
});
$("#<%=peopleNames.ClientID%>").result(function (event, data, formatted) {
alert('ok');
if (data) {
alert($(this).parent().next().find("input").val(data[1]));
}
});
});
</script>
</head>
<body>
<form runat="server">
<asp:TextBox ID="peopleNames" runat="server" MaxLength="500"></asp:TextBox>
</form>
</body>
</html>
只是为了测试目的,想法是让网络用户输入一个名字,jQuery 会调用 WCF 服务http://localhost/MyService/GetPeople 来列出 SQL Server 数据库中的所有人员(将来 GetPeople 方法将有一个字符串参数)。
jquery autocomplete 插件似乎不错,但我还不确定需要哪些 js 文件才能使其在本地计算机上运行。现在我无法让它工作或调试它,即使是在显示 alert();
【问题讨论】:
-
Person Class 中的 [DataConctract] [DataMember] 属性呢?
-
完成。我看到 WCF 运行良好。我正在查看jqueryui.com/demos/autocomplete/#remote 看看发生了什么
标签: asp.net jquery wcf autocomplete