我正在寻找使用Asp.Net Web方法使用Typeahead.js的示例。
我有http://twitter.github.io/typeahead.js/examples/使用基本示例的示例,但我不完全了解如何使用asp.net webmethod实现Bloodhound功能。
typeahead函数正在调用WebMethod(我可以看到调试器中的步骤)但是没有返回到TypeAhead列表的内容。
这是标记:
<div class="input-group">
<asp:TextBox ID="tboxText" runat="server" CssClass="form-control autocomplete" placeholder="Look Up"></asp:TextBox>
<span class="input-group-btn">
<asp:Button ID="btnAddItem" runat="server" Text="Add" CssClass="btn btn btn-amethyst" />
</span>
</div>
这是jquery:
$(document).ready(function () {
var textlookup = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: '/WebServices/InternalMethods.asmx/TextAutocomplete?param=%QUERY'
});
textlookup.initialize();
$('.autocomplete').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'textlookup',
displayKey: 'value',
source: textlookup.ttAdapter()
});
});
这是WebMethod:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<string> TextAutocomplete(string param)
{
return Suggestions.TextAutocomplete(param);
}
感谢任何帮助。
答案 0 :(得分:0)
看起来您可能需要将参数作为c#中的查询字符串获取。尝试使用return Suggestions.TextAutocomplete(Request.QueryString [&#34; param&#34;]);