不显示长度已过期的记录

时间:2019-08-30 21:53:53

标签: javascript html arrays reactjs redux

update1 :我在沙盒中尝试过它还返回空的:( https://codesandbox.io/s/happy-https-u8lu2

  • 当我用身高和体重过滤我的starsValue时,我得到的结果。

  • 在这种情况下,我不应该显示长度已过期的记录

  • 所以我在过滤器中写了以下条件。 (searchFilter.length && !searchFilter.length[0].expired == 'Y') &&
  • 但是我没有得到想要的值。
  • 我试图通过将控制台放入过滤器进行调试。
  • 但没有任何帮助。
  • 你能告诉我如何解决它吗?
  • 在下面提供我的代码段
filteredResult = nextprops.starsValues
                .filter(
                searchFilter =>

                   // (searchFilter.length && !searchFilter.length[0].expired == 'Y') &&
                    searchFilter.height === this.props.data.height &&
                    searchFilter.weight === this.props.data.weight
                // }
                )
                .map(search => {
                    console.log('search-->', search);
                    let spec = '';
                    let specialities = this.props.length.find(
                        page => page.homeId == search.homeId
                    );
                    if (specialities && specialities.specialties) {
                        spec = specialities.specialties;
                    }
                    //                        | ${search.length[0].number}

                    return {
                        label: `${search.fdfdgs}
                        | ${search.height}
                        | ${spec}
                        | ${search.weight}

                        `,
                        value: search.weight,
                        checked: true,
                    };
                });

[
  {
    "homeId": 434343,
    "fdds": 8063737,
    "rerefe": "154964746045100",
    "fsf": "2019-02-08 19:02:31",
    "height": "fddfdf",
    "sdsdds": "fd",
    "weight": "8989989832",
    "weightType": "EIN",
    "fdfdgs": "fd",
    "formattedweight": "89899889",
    "dfsf": "fd",
    "length": [
      {
        "number": "6767"
      }
    ],
    "refrefre": [
      {
        "number": "332322323"
      }
    ],
    "stth": [
      {
        "number": "l;l;;l",
        "expired": "Y"
      },
      {
        "number": "107125"
      },
      {
        "number": "323232"
      }
    ],
    "sortColumn": "6767"
  },
  {
    "homeId": 233232,
    "fdds": 8336007,
    "rerefe": "155410986184100",
    "fsf": "2019-04-01 19:01:54",
    "height": "rerere",
    "sdsdds": "gfdfgfg",
    "weight": "8989989832",
    "weightType": "EIN",
    "fdfdgs": "gfdfgfg",
    "formattedweight": "89899889",
    "dfsf": "gfdfgfg",
    "sortColumn": ""
  },
  {
    "homeId": 656,
    "fdds": 8519423,
    "rerefe": "155612474568800",
    "fsf": "2019-04-24 18:04:41",
    "height": "fddfdf",
    "sdsdds": "gfdfgfg",
    "weight": "8989989832",
    "weightType": "EIN",
    "fdfdgs": "gfdfgfg",
    "formattedweight": "89899889",
    "dfsf": "gfdfgfg",
    "length": [
      {
        "number": "119"
      }
    ],
    "refrefre": [
      {
        "number": "88998"
      }
    ],
    "stth": [
      {
        "number": "4063",
        "expired": "Y"
      },
      {
        "number": "100001"
      },
      {
        "number": "6819"
      }
    ],
    "sortColumn": "119"
  },
  {
    "homeId": 6565,
    "fdds": 8648222,
    "rerefe": "155677756668200",
    "fsf": "2019-05-02 19:05:49",
    "height": "fggfgffg",
    "sdsdds": "gfdfgfg",
    "weight": "8989989832",
    "weightType": "EIN",
    "fdfdgs": "gfdfgfg",
    "formattedweight": "89899889",
    "dfsf": "gfdfgfg",
    "length": [
      {
        "number": "6A0BO"
      }
    ],
    "refrefre": [
      {
        "number": "1851892467"
      }
    ],
    "sortColumn": "6A0BO"
  },
  {
    "homeId": 6556,
    "fdds": 7102392,
    "rerefe": "153216057385900",
    "fsf": "2018-07-21 06:07:27",
    "height": "fddfdf",
    "sdsdds": "8989898",
    "weight": "8989989832",
    "weightType": "EIN",
    "fdfdgs": "8989898",
    "formattedweight": "89899889",
    "dfsf": "8989898",
    "length": [
      {
        "number": "L8P"
      }
    ],
    "refrefre": [
      {
        "number": "1730277229"
      }
    ],
    "stth": [
      {
        "number": "088088008"
      },
      {
        "number": "105961"
      }
    ],
    "sortColumn": "L8P"
  },
  {
    "homeId": 4545,
    "fdds": 8663767,
    "rerefe": "155717411337700",
    "fsf": "2019-05-06 19:04:04",
    "height": "fddfdf",
    "sdsdds": "gfgfgfgf",
    "weight": "8989989832",
    "weightType": "EIN",
    "fdfdgs": "gfgfgfgf",
    "formattedweight": "89899889",
    "dfsf": "gfgfgfgf",
    "length": [
      {
        "number": "OM2"
      }
    ],
    "stth": [
      {
        "number": "4063",
        "expired": "Y"
      }
    ],
    "sortColumn": "OM2"
  },
  {
    "homeId": dfdffd,
    "fdds": 8336007,
    "rerefe": "155410986184100",
    "fsf": "2019-04-01 19:01:54",
    "height": "fddfdf",
    "sdsdds": "yuiuyuy",
    "weight": "8989989832",
    "weightType": "EIN",
    "fdfdgs": "yuiuyuy",
    "formattedweight": "89899889",
    "dfsf": "yuiuyuy",
    "length": [
      {
        "number": "4334",
        "expired": "Y"
      }
    ],
    "refrefre": [
      {
        "number": "6565"
      }
    ],
    "stth": [
      {
        "number": "3443"
      },
      {
        "number": "4343"
      }
    ],
    "sortColumn": "3443"
  }
]

1 个答案:

答案 0 :(得分:0)

您的问题出在表达式上

(searchFilter.length && !searchFilter.length[0].expired == 'Y')

特别是:

!searchFilter.length[0].expired == 'Y'

操作顺序为:

1)对searchFileter.length[0] // 'Y'

的评估

2)取反此值// false

3)等同于'Y' // false == 'Y' ====> false

解决方法是将表达式放在括号中,然后取反:

searchFilter.length && !(searchFilter.length[0].expired == 'Y')

这可以解决您的问题吗?