JavaScript Error: 'item.parentId.includes is not a function' - Troubleshooting and Solution
The error message 'item.parentId.includes is not a function' indicates that the 'includes' method is not available for the 'parentId' property of the 'item' object. This usually occurs when 'item.parentId' is not a string, and the 'includes' method is only applicable to strings.
To fix this issue, you should check if 'item.parentId' is a string before using the 'includes' method. Here's the updated code:
handleQuery(item) {
console.log(item, 'item');
if (this.searchvalue) {
return this.voucherGroupList.filter((item) => {
if (item.voucherGroupCode && typeof item.parentId === 'string') {
// Check if item.parentId is a string before using includes method
return (
item.voucherGroupCode.includes(this.searchvalue) ||
item.parentId.includes(this.searchvalue)
);
}
});
} else {
return this.voucherGroupList;
}
}
By adding the typeof item.parentId === 'string' condition, the code ensures that the 'includes' method is only used when the 'parentId' property is a string, effectively preventing the error.
原文地址: http://www.cveoy.top/t/topic/qwRO 著作权归作者所有。请勿转载和采集!