作者:冬-冰释_488 | 来源:互联网 | 2022-11-21 02:38
我正在尝试使用以下代码渲染过滤数据:
const notes = [{
title: "Order cat food",
body: "Get 1 kg."
},
{
title: "Clean kitchen",
body: "The fridge door."
},
{
title: "Buy groceries",
body: "Remember the yellow and red pepper."
},
{
title: "Go to the gym",
body: "Exercise for 2hrs."
},
{
text: "Make porridge",
body: "Remember to put lime and honey."
}]
const allfilters = {
searchText: ""
}
const renderNotes = function(notes, filters) {
const filteredNotes = notes.filter(function (note) {
return note.title.toLowerCase().includes(filters.searchText.toLowerCase());
})
console.log(filteredNotes);
}
renderNotes(notes, allfilters);
document.querySelector('#to-do').addEventListener('input', function(e) {
allfilters.searchText = e.target.value;
renderNotes(notes, allfilters);
})
运行后,我收到错误,"无法读取未定义的属性'小写'."
我错过了什么?
1> connexo..:
{
text: "Make porridge",
body: "Remember to put lime and honey."
}
你的最后一个数组项目没有title
,而是它有text
,所以
note.title.toLowerCase()
该数组项目note.title
是undefined
.toLowerCase()
不存在undefined
.
鹰眼...... +1