[英]TokenInput + Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
I want to create a textbox with pre-defined possible values but I ended up with getting an error: 我想创建一个具有预定义可能值的文本框,但最终出现错误:
Uncaught TypeError: Cannot read property 'toLowerCase' of undefined 未捕获的TypeError:无法读取未定义的属性“ toLowerCase”
I try to use Token Input script ( http://loopj.com/jquery-tokeninput/ ) but I failed to read data from the database. 我尝试使用令牌输入脚本( http://loopj.com/jquery-tokeninput/ ),但是我无法从数据库读取数据。 I'm working with .NET MVC. 我正在使用.NET MVC。
Here's my method (in Model) to read data: 这是我的方法(在Model中),用于读取数据:
public List<CRMClientsModel> CRMClientsModel() {
var sqlConnect = DbConnectHelper.GetDbInstance<SqlConnection>();
var query = string.Format("SELECT CompanyName,Id from Company");
return sqlConnect.Query<CRMClientsModel>(query).ToList();
}
And here the part of controller responsible for conversion of data to JSON format 这是控制器中负责将数据转换为JSON格式的部分
CRMLogic Logic = new CRMLogic();
CRMModel Model = new CRMModel();
List<CRMClientsModel> Clients = Logic.CRMClientsModel().ToList();
List<CRMClientViewModel> ClientsVM = Clients.Select(a => a.ToViewModel<CRMClientViewModel>()).ToList();
Model.CRMClientsModel = Clients;
CRMViewModel ViewModel = new CRMViewModel();
ViewModel.CRMClientsModel = ClientsVM;
JavaScriptSerializer jsonSerialiser = new JavaScriptSerializer();
string json = jsonSerialiser.Serialize(ClientsVM);
ViewModel.jsonproject = json;
Then in View it's called by 然后在View中被称为
<script type="text/javascript">
$(window).ready(function () {
@*var item = @Html.Raw(Model.jsonproject)
alert(item)*@
$("#inputproject").tokenInput(@Html.Raw(Model.jsonproject),
{
theme: "facebook", minChars: 0
});
});
</script>
Got it. 得到它了。 It turned out that the error was caused by missing "propertyToSearch". 原来,该错误是由于缺少“ propertyToSearch”引起的。 Similar issue below: jQuery-tokeninput failing: "term" is undefined? 下面类似的问题: jQuery-tokeninput失败:“术语”未定义?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.