【发布时间】:2015-08-18 16:58:48
【问题描述】:
我正在尝试在 asp.net 网络表单应用程序中实现 typeahead.js。
我有一个通用处理程序,它返回字符串列表,在我的例子中,是学校的名称。
这是处理程序的代码:
public void ProcessRequest(HttpContext context)
{
List<string> strSchools = new List<string>();
string prefixText = context.Request.QueryString["q"];
var schools =
DataLayer.GetSchools()
.Select(s => s).OrderBy(s => s.Name);
foreach (SchoolItem school in schools)
{
if (prefixText != string.Empty)
{
prefixText = prefixText.ToLower();
if (school.Name.ToLower().Contains(prefixText))
{
strSchools.Add(school.Name);
}
}
else
{
strSchools.Add(school.Name);
}
}
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
context.Response.Write(jsSerializer.Serialize(strSchools));
}
在 js 代码中我有这个:
function pageLoad(sender, args) {
var schoolList = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('names'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
remote: 'SchoolListHandler.ashx'
});
// kicks off the loading/processing of `local` and `prefetch`
schoolList.initialize();
// debugger;
// passing in `null` for the `options` arguments will result in the default
// options being used
$('#txtSchool').typeahead(null, {
name: 'name',
displayKey: 'Name',
// `ttAdapter` wraps the suggestion engine in an adapter that
// is compatible with the typeahead jQuery plugin
source: schoolList.ttAdapter()
});
}
由于某种原因,正如我所说,我无法到达处理程序并取回结果。
你们觉得有什么不对吗?
【问题讨论】:
-
你能提到你遇到的错误吗?
标签: javascript jquery asp.net typeahead.js typeahead