我想使用typeahead.js,但我无法通过asp.net mvc实现它。
这里是JS代码:
var $SelectedSuggestion = $('#selectedCompany').hide(),
movies = new Bloodhound({
datumTokenizer: function (datum) {
return Bloodhound.tokenizers.whitespace(datum.title);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/Home/getTags',
filter: function (movies) {
return movies.results;
}
}
});
// Initialize the Bloodhound suggestion engine
movies.initialize();
// Instantiate the Typeahead UI
$('#inputTags').typeahead(null, {
displayKey: 'title',
source: movies.ttAdapter()
})
.on("typeahead:selected", function (obj, selectedItem) {
$SelectedSuggestion.html("Selected Suggestion Item: " + JSON.stringify(selectedItem)).show();
});
asp mvc controller:
[RequireHttps]
public ActionResult getTags()
{
Tag tg = new Tag();
return Json(tg.getSTags());
}
这是我选择数据的功能:
public Array getSTags()
{
TimaitEntities database = new TimaitEntities();
var db = database;
return (from x in db.superTag select x.name).ToArray();
}
我的问题是getSTags()
的正确数据类型是什么,我的控制器是否正确?
另见JS中的这一行:
url: '/Home/getTags',