【发布时间】:2019-01-16 23:54:14
【问题描述】:
我设置了一个搜索栏,我想要做的是,当您搜索某些内容时,它会执行 axios get 调用,它会过滤所有结果并只为您提供您正在搜索的内容。
axios.get("api/blogs/" + this.state.pageIndex + "/10").then(res => {
res.filter(function(author) {
return author.firstName === this.state.query;
});
});
我正在使用反应。
【问题讨论】:
-
您的预期输出是什么,您现在的输出有什么问题?
-
我想你一定是得到
this.state is undefined,对吗? -
因为
res.filter(...)里面的javascript context不是react对象,即this不指向react对象并且所以你无法访问this.state -
res.filter(function(author) {改为res.filter((author) => {使用箭头功能