typeahead 自动完成抛出错误
typeahead Autocomplete Throwing error
您好,我正在尝试在我的 MVC 项目
中使用 "typeahead.js" 类似 http://sriniavatar.com/bootstrap-typeahead-in-asp-net-mvc/ 的东西来实现自动完成文本框
我的脚本如下
<script type="text/javascript">
var substringMatcher = function (strs) {
return function findMatches(q, cb) {
var matches, substringRegex;
matches = [];
substrRegex = new RegExp(q, 'i');
$.each(strs, function (i, str) {
if (substrRegex.employees(str)) {
matches.push(str);
}
});
cb(matches);
};
};
$.post('/Employee/TagSearch', null, function (data) {
var employees = data;
$('#sriniavatar').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'employees',
displayKey: 'value',
source: substringMatcher(employees)
});
});
下面给出了我的员工控制器的 TagSearch 方法
[HttpPost]
public ActionResult TagSearch(string term)
{
DataAccess db = new DataAccess();
var employees = db.GetEmployeesName().ToList();
//if (!String.IsNullOrEmpty(term))
//{
// employees = employees.Where(e => e.Surname.Contains(term.Trim())
// || e.ForeName.Contains(term.Trim())
// || e.Win_UserName.Contains(term.Trim())
// ).ToList();
//}
return Json(employees, JsonRequestBehavior.AllowGet);
}
现在 **问题是,当我在 运行 程序中显示以下错误 *"http://localhost:57512/Employee/ViewEmployees
第 21 行第 95 行未处理的异常
0x800a01b6 - JavaScript 运行时错误:对象不支持 属性 或方法 'employees'”***
尽管我在我的项目中引用了以下脚本
<link href="~/Content/typeahead.css" rel="stylesheet" /> <script "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script> <script src="~/Scripts/typeahead.js"></script> <br/>...Page Contents...<br>
<script src="~/Scripts/typeahead.mvc.model.js"></script>
@RenderSection("scripts", required: false)
我不知道有任何 JavaScript 具有使用 regExp
的员工方法
if (substrRegex.employees(str)) {
^^^^^^^^^
我相信你想要test
if (substrRegex.test(str)) {
您好,我正在尝试在我的 MVC 项目
我的脚本如下
<script type="text/javascript">
var substringMatcher = function (strs) {
return function findMatches(q, cb) {
var matches, substringRegex;
matches = [];
substrRegex = new RegExp(q, 'i');
$.each(strs, function (i, str) {
if (substrRegex.employees(str)) {
matches.push(str);
}
});
cb(matches);
};
};
$.post('/Employee/TagSearch', null, function (data) {
var employees = data;
$('#sriniavatar').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'employees',
displayKey: 'value',
source: substringMatcher(employees)
});
});
下面给出了我的员工控制器的 TagSearch 方法
[HttpPost]
public ActionResult TagSearch(string term)
{
DataAccess db = new DataAccess();
var employees = db.GetEmployeesName().ToList();
//if (!String.IsNullOrEmpty(term))
//{
// employees = employees.Where(e => e.Surname.Contains(term.Trim())
// || e.ForeName.Contains(term.Trim())
// || e.Win_UserName.Contains(term.Trim())
// ).ToList();
//}
return Json(employees, JsonRequestBehavior.AllowGet);
}
现在 **问题是,当我在 运行 程序中显示以下错误 *"http://localhost:57512/Employee/ViewEmployees
第 21 行第 95 行未处理的异常0x800a01b6 - JavaScript 运行时错误:对象不支持 属性 或方法 'employees'”***
尽管我在我的项目中引用了以下脚本
<link href="~/Content/typeahead.css" rel="stylesheet" /> <script "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script> <script src="~/Scripts/typeahead.js"></script> <br/>...Page Contents...<br>
<script src="~/Scripts/typeahead.mvc.model.js"></script>
@RenderSection("scripts", required: false)
我不知道有任何 JavaScript 具有使用 regExp
的员工方法if (substrRegex.employees(str)) {
^^^^^^^^^
我相信你想要test
if (substrRegex.test(str)) {