我正在寻找一个使用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>
Run Code Online (Sandbox Code Playgroud)
这是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()
});
});
Run Code Online (Sandbox Code Playgroud)
这是WebMethod:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<string> TextAutocomplete(string param)
{
return Suggestions.TextAutocomplete(param);
}
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.