更改搜索过滤器的错误在哪里?以及如何修复它? [英] Where did I make the mistake of changing my search filter? And how to fix it?
问题描述
我有一个起飞或抵达机场的飞机列表,我还有一个搜索过滤器,我可以在其中输入飞机的抵达或起飞时间和过滤器.我使用 API 的 actual
属性执行此操作.但我需要改变我的搜索.现在我需要按航班号搜索 - 我的 API 的 planeTypeID.code
属性.但是当我改变它时,停止显示飞机列表.我的错误是什么以及如何解决?
我只是用 actual
到处写了 ["planeTypeID.code"]
和删除方法:.split("-").reverse().join("-")
旧版本:
小部分airplane.js(reducer)
case "RUN_FILTER":var newData = state.data[action.shift ||state.shift].filter(x => {返回 (x.实际&&x.actual.includes(状态日.分裂("-").撤销().加入("-")));});案例LOAD_DATA_END":var newData = action.payload.data[state.shift].filter(x => {返回 (x.实际&&x.actual.includes(action.payload.day.分裂("-").撤销().加入("-")));});
小部分 app.js(主要组件)
导出函数 searchFilter(search, data) {返回 data.filter(n => n.actual.toLowerCase().includes(search));}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
新版本:
小部分airplane.js(reducer)
case "RUN_FILTER":var newData = state.data[action.shift ||state.shift].filter(x => {返回 (x["planeTypeID.code"] &&//改变x["planeTypeID.code"].includes(//改变状态日//删除));});返回 Object.assign({}, state, {案例LOAD_DATA_END":var newData = action.payload.data[state.shift].filter(x => {返回 (x["planeTypeID.code"] &&//改变x["planeTypeID.code"].includes(//改变action.payload.day//删除));});
小部分 app.js(主要组件)
<预><代码>导出函数searchFilter(搜索,数据){返回 data.filter(n => n["planeTypeID.code"].toLowerCase().includes(search));//改变}沙箱中的所有项目代码:
https://codesandbox.io/s/redux-ant-design-filter-table-column-with-slider-jj6mu
x["planeTypeID.code"]
的示例值为 state.day
的B734"代码> "23-08-2019" => 那些是 2 个不同的字段 => 当你通过 x["planeTypeID.code"].includes(state.day)
过滤时,你会得到一个空数组¯\_(ツ)_/¯
通过注释调试后,最可能的解决方案是:
x["planeTypeID.code"].toLowerCase().includes(action.search || state.search)
<小时>
我建议将开始调试 JavaScript 作为通用问题的第一步:
<块引用>我哪里出错了...
...在发布到 Stack Overflow 之前.
I have a list of airplanes departing or arriving at the airport and i also had a search filter where i enter the time of arrival or departure and filtering of the airplanes. I do this using the actual
property of my API. But I needed to change my search. Now I need to search by flight number - the planeTypeID.code
property of my API. But when I changed it, stopped showing a list of airplanes. What is my mistake and how to fix it?
I just instead actual
everywhere wrote ["planeTypeID.code"]
and delete method:
.split("-").reverse().join("-")
OLD version:
small part airplane.js(reducer)
case "RUN_FILTER":
var newData = state.data[action.shift || state.shift].filter(x => {
return (
x.actual &&
x.actual.includes(
state.day
.split("-")
.reverse()
.join("-")
)
);
});
case "LOAD_DATA_END":
var newData = action.payload.data[state.shift].filter(x => {
return (
x.actual &&
x.actual.includes(
action.payload.day
.split("-")
.reverse()
.join("-")
)
);
});
small part app.js(main component)
export function searchFilter(search, data) {
return data.filter(n => n.actual.toLowerCase().includes(search));
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
NEW version:
small part airplane.js(reducer)
case "RUN_FILTER":
var newData = state.data[action.shift || state.shift].filter(x => {
return (
x["planeTypeID.code"] && // Сhange
x["planeTypeID.code"].includes( // Сhange
state.day
// delete
)
);
});
return Object.assign({}, state, {
case "LOAD_DATA_END":
var newData = action.payload.data[state.shift].filter(x => {
return (
x["planeTypeID.code"] && // Сhange
x["planeTypeID.code"].includes( // Сhange
action.payload.day
// delete
)
);
});
small part app.js(main component)
export function searchFilter(search, data) {
return data.filter(n => n["planeTypeID.code"].toLowerCase().includes(search)); // Сhange
}
All project code in sandbox:
https://codesandbox.io/s/redux-ant-design-filter-table-column-with-slider-jj6mu
An example value of x["planeTypeID.code"]
is "B734", of state.day
"23-08-2019" => those are 2 different fields => you will get an empty array when you filter by x["planeTypeID.code"].includes(state.day)
¯\_(ツ)_/¯
After debugging via comments, the most likely solution is:
x["planeTypeID.code"].toLowerCase().includes(action.search || state.search)
I recommend to Get Started with Debugging JavaScript as a generic first step to questions that start with:
Where did I make the mistake...
...before posting to Stack Overflow.
这篇关于更改搜索过滤器的错误在哪里?以及如何修复它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!