我无法弄清楚为什么这会作为错误返回。
item.Question.toUpperCase 不是函数
我在我的 expo 应用程序中使用 react 收到此错误,但在控制台中没有抛出任何错误
错误:
TypeError: item.Question.toUpperCase 不是函数。in
item.Question.toUpperCase()
item.Question.toUpperCase
未定义
我尝试创建新变量为
var Question = item.Question.toUpperCase()
但这似乎不起作用所以这里是完整的代码
else if(item.Title == undefined){
const itemData = `${item.Question.toUpperCase()} ${item.answer.toUpperCase()} ${item.keyword.toUpperCase()}`;
const textData = search.toUpperCase();
return itemData.indexOf(textData) > -1;
item 是一个对象,其中 Question 是一个字符串
谢谢
编辑:所以经过一些记录后,我发现这个区域给出了错误:
console.log(item.keyword,item.Title)
console.log(typeof item.Question, item.Question)
const itemData = `${item.Title.toUpperCase()} ${item.Question.toUpperCase()} ${item.answer.toUpperCase()} ${item.keyword.toUpperCase()}`;
const textData = search.toUpperCase();
console.log(typeof itemData,typeof textData)
当记录 item.Question 和我得到的数字和 NaN 类型时,这很奇怪,因为它应该从我的数据库中提取字符串“这是一个 strng10” 对数据库的所有其他调用似乎都工作正常。他们为 item.Question 提供了正确的类型作为字符串。
所以我想我要解决的问题是如何将字符串转换为 NaN 的数字?