我正在寻找将 Typeahead.js 与 Asp.Net Webmethod 一起使用的示例。
我有来自的例子http://twitter.github.io/typeahead.js/examples/ 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);
}
任何帮助表示赞赏。