未捕获的TypeError:无法使用'in'运算符在JSON字符串中搜索'' [英] Uncaught TypeError: Cannot use 'in' operator to search for '' in JSON string
本文介绍了未捕获的TypeError:无法使用'in'运算符在JSON字符串中搜索''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的网站上使用了令牌输入,这是我如何初始化令牌输入:
I've use token input in my website, and here's how I initialize the token input:
$(document).ready(function () {
var populateValue = document.getElementById('<%= hiddentokenPrePopulate.ClientID%>').value
$("#<%= tokenEmployee.ClientID%>").tokenInput("../Employee/getEmployeeDetails.ashx", {
deleteText: "X",
theme: "facebook",
preventDuplicates: true,
tokenDelimiter: ";",
minChars: 3,
tokenLimit: 1,
prePopulate: populateValue
});
});
脚本停留在这一行:
prePopulate: populateValue
当我删除此行时,不会有任何javascript错误,但我需要这个,因为我需要预先填充令牌输入。 populateValue
是:
When I remove this line, there won't be any javascript error, but I need this as I need to pre-populate the token input. The populateValue
is:
[{
"id": "11566",
"name": "Smith - White"
}]
有一个javascript错误:
There was a javascript error:
未捕获TypeError:无法使用'in'运算符在[{中搜索'47' id:11566,name:Smith - White}]`
Uncaught TypeError: Cannot use 'in' operator to search for '47' in [{"id":"11566","name":"Smith - White"}]`
如何修复此错误?
推荐答案
您需要将 populateValue
变量中的字符串解析为对象:
You need to parse the string in your populateValue
variable to an object:
prePopulate: $.parseJSON(populateValue)
或者,在普通JS中:
prePopulate: JSON.parse(populateValue)
这篇关于未捕获的TypeError:无法使用'in'运算符在JSON字符串中搜索''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文