Javascript React Native无法过滤道具
我目前正在react native和redux中构建一个搜索栏,但无法以文本输入过滤的格式通过我的道具Javascript React Native无法过滤道具,javascript,reactjs,filter,react-native,redux,Javascript,Reactjs,Filter,React Native,Redux,我目前正在react native和redux中构建一个搜索栏,但无法以文本输入过滤的格式通过我的道具 onInput(text) { this.setState({ text, }); /* Search after user stop typing */ clearTimeout(this.inputDelay); this.inputDelay = setTimeout(() => { this.getResult(t
onInput(text) {
this.setState({
text,
});
/* Search after user stop typing */
clearTimeout(this.inputDelay);
this.inputDelay = setTimeout(() => {
this.getResult(text);
}, 1000);
}
getResult(text) {
if (text.length > 0) {
const { entitiesList } = this.props;
const { dataSource } = this.state;
console.log(this.props.entitiesList); // returns object containing an array
const reg = new RegExp(text, 'i');
const entities = entitiesList.filter((entity) => {
return reg.test(entity.fullName);
});
this.setState({
dataSource: dataSource.cloneWithRows(entities),
});
}
未处理的JS异常:\u this3.props.entitiesList.filter不是一个函数
被抛出。This.props.entitiesList确实返回了一个对象,因此我不确定我的错误在哪里
{ performances:
[ { _id: '5893b419d2b38b7122dc24f6',
fullName: 'Brett Monroe',
Z3_performance_Id: '696395',
A_relationship_Place: '1.',
N_event_Division: 'Varsity',
F_performance_Mark: '19.05',
C_athlete_Id: '273452',
},
{...},
{...}
]
}
任何提示/指点都非常感谢 原因是
实体列表
是一个对象
,您不能直接在对象
上使用过滤器
或任何其他迭代器,如映射、forEach
等entitiesList
包含一个键performances
,即数组
,因此您需要像这样使用它:
const entities = entitiesList.performances.filter((entity) => {
return reg.test(entity.fullName);
});
能否显示控制台中打印的
this.props.entitiesList
的值?{performances:[{id:'5893b419d2b38b7122dc24f6',L_段编号:'1',N_impl_Division:null,全名:'Brett Monroe',Z3_performance_id:'696395',A_relationship_Place:'1',N_event_Division:'Varsity',F_performance_Mark:'11.05a',C_运动员id:'A5273452',}。。