gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot use 'in' operator to search for '' in JSON string

转载 作者:可可西里 更新时间:2023-11-01 01:27:06 25 4
gpt4 key购买 nike

我在我的网站中使用了 token 输入,下面是我如何初始化 token 输入:

$(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 错误,但我需要它,因为我需要预填充 token 输入。 populateValue 是:

[{
"id": "11566",
"name": "Smith - White"
}]

有一个 javascript 错误:

Uncaught TypeError: Cannot use 'in' operator to search for '47' in [{"id":"11566","name":"Smith - White"}]`

我该如何修复这个错误?

最佳答案

您需要将 populateValue 变量中的字符串解析为一个对象:

prePopulate: $.parseJSON(populateValue)

或者,在普通 JS 中:

prePopulate: JSON.parse(populateValue)

关于javascript - 未捕获的类型错误 : Cannot use 'in' operator to search for '' in JSON string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23673184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com