Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 按按钮选择多个过滤器_Javascript_Reactjs_Button_Filter - Fatal编程技术网

Javascript 按按钮选择多个过滤器

Javascript 按按钮选择多个过滤器,javascript,reactjs,button,filter,Javascript,Reactjs,Button,Filter,我需要帮助按类型筛选多个数组:收入或支出,上个月的交易和价值超过1000的交易。 我有纽扣 组件按钮: <div className="buttons"> {buttons.map(item => ( <button variant="outline-primary" key={item.id} className={item.btnClass} type="button"

我需要帮助按类型筛选多个数组:收入或支出,上个月的交易和价值超过1000的交易。 我有纽扣 组件按钮:

<div className="buttons">
    {buttons.map(item => (
      <button
        variant="outline-primary"
        key={item.id}
        className={item.btnClass}
        type="button"
        onClick={() => {
          filterData(item.type, item.parameter, item.id);
        }}
      >
        {item.label}
      </button>
按钮

const buttons = [{
       id: 0,
       label: 'income',
       type: 'incomeFilter',
       parameter: 'income',
       btnClass: ''
      },
      {
      id: 1,
      label: 'outlay',
      type: 'outlayFilter',
      parameter: 'outlay',
      btnClass: ''
      },
      {
      id: 2,
      label: 'last month',
      type: 'date',
      parameter: '',
      btnClass: ''
      },
      {
      id: 3,
      label: 'more 1000',
      type: 'value',
      parameter: '1000',
      btnClass: ''
      }];
我想不出使用该函数过滤表的算法。
我试图添加额外的数组,但一切都很笨拙

当涉及到筛选/排序数组时,您应该利用

例如,将收入从最低到最高排序

filterData = (type, parameter, id) => {
  const sortedArr = this.state.transtactions
                      .filter(transaction => transaction.type === type)
                        .sort(function(a, b) {return a.value - b.value});
}
请试试这个:

filterData(类型、参数、id){
设temp=[];
如果(类型==“日期”){
让今天=新日期();
换热器(换热器){
如果(t.date.getMonth()==today.getMonth()){
温度推力(t);
}
}
}else if(类型=='value'){
换热器(换热器){
如果(t.值>1000){
温度推力(t);
}
}
}
这是我的国家({
过滤传输:温度
});
}
filterData = (type, parameter, id) => {
  const sortedArr = this.state.transtactions
                      .filter(transaction => transaction.type === type)
                        .sort(function(a, b) {return a.value - b.value});
}