• <small id='xQUV3'></small><noframes id='xQUV3'>

    1. <i id='xQUV3'><tr id='xQUV3'><dt id='xQUV3'><q id='xQUV3'><span id='xQUV3'><b id='xQUV3'><form id='xQUV3'><ins id='xQUV3'></ins><ul id='xQUV3'></ul><sub id='xQUV3'></sub></form><legend id='xQUV3'></legend><bdo id='xQUV3'><pre id='xQUV3'><center id='xQUV3'></center></pre></bdo></b><th id='xQUV3'></th></span></q></dt></tr></i><div id='xQUV3'><tfoot id='xQUV3'></tfoot><dl id='xQUV3'><fieldset id='xQUV3'></fieldset></dl></div>

    2. <tfoot id='xQUV3'></tfoot>

        <bdo id='xQUV3'></bdo><ul id='xQUV3'></ul>
    3. <legend id='xQUV3'><style id='xQUV3'><dir id='xQUV3'><q id='xQUV3'></q></dir></style></legend>

        如何创建一个多重过滤功能来过滤掉多个属性?

        时间:2023-09-06

        <i id='uiTc7'><tr id='uiTc7'><dt id='uiTc7'><q id='uiTc7'><span id='uiTc7'><b id='uiTc7'><form id='uiTc7'><ins id='uiTc7'></ins><ul id='uiTc7'></ul><sub id='uiTc7'></sub></form><legend id='uiTc7'></legend><bdo id='uiTc7'><pre id='uiTc7'><center id='uiTc7'></center></pre></bdo></b><th id='uiTc7'></th></span></q></dt></tr></i><div id='uiTc7'><tfoot id='uiTc7'></tfoot><dl id='uiTc7'><fieldset id='uiTc7'></fieldset></dl></div>
          • <small id='uiTc7'></small><noframes id='uiTc7'>

              <tfoot id='uiTc7'></tfoot>
            1. <legend id='uiTc7'><style id='uiTc7'><dir id='uiTc7'><q id='uiTc7'></q></dir></style></legend>

                  <tbody id='uiTc7'></tbody>

                  <bdo id='uiTc7'></bdo><ul id='uiTc7'></ul>

                  本文介绍了如何创建一个多重过滤功能来过滤掉多个属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个要过滤的对象数组:

                  I have an array of objects to be filtered:

                  [
                    {
                      "name": "Apple",
                      "age": 24,
                      "model": "Android",
                      "status": "Under development",
                    },
                  
                    {
                      "name": "Roboto",
                      "age": 24,
                      "model": "Apple",
                      "status": "Running",
                    },
                    
                    .
                    .
                    .
                    .
                  
                  ]  
                  

                  我需要使用 JavaScript 的 filter 方法使用多个参数过滤数组.我得到了部分解决方案,但无法获得预期的输出.

                  I need to filter the array using multiple parameters using JavaScript's filter method. I have got a partial solution but could not get the expected output.

                  过滤器还应该适用于单个属性的多个值.例如,age=54,23model=Android"、Apple" 等.

                  The filter should also work with multiple values for a single attribute. E.g., age=54,23 or model="Android","Apple" etc.

                  我试图模仿电子商务网站的过滤器的工作方式,我们可以在其中比较产品的所有属性和客户选择的标签,以输出过滤后的产品列表.

                  I'm trying to mimic the working of filters just like that of an e-commerce site, where we can compare all of a product’s attributes and customer’s chosen tags to output a filtered list of products.

                  推荐答案

                  如果您像数据数组中的对象一样格式化过滤条件,但值是可能值的数组,那么您可以使用filter方法如下:

                  If you format your filter conditions just like an object in your data array, but with values being arrays of possible values, then you can use the filter method as follows:

                  let data = [
                    {
                      "name": "Apple",
                      "age": 24,
                      "model": "Android",
                      "status": "Under development",
                    }, {
                      "name": "Roboto",
                      "age": 24,
                      "model": "Apple",
                      "status": "Running",
                    }, {
                      "name": "Samsung",
                      "age": 26,
                      "model": "Blueberry",
                      "status": "Running",
                    },
                  ];
                  
                  let filter = {
                      "name": ["Roboto", "Ericsson"],
                      "age": [22, 24, 26],
                  };
                  
                  let res = data.filter(obj =>
                      Object.entries(filter).every(([prop, find]) => find.includes(obj[prop])));
                      
                  console.log(res);

                  这篇关于如何创建一个多重过滤功能来过滤掉多个属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何创建与背景渐变和重叠透明形状一起使用的嵌入弯曲背景? 下一篇:在 node js 服务器的终端中无法识别 nodemon 命令

                  相关文章

                  <legend id='d7VDF'><style id='d7VDF'><dir id='d7VDF'><q id='d7VDF'></q></dir></style></legend>
                    <tfoot id='d7VDF'></tfoot>

                    1. <small id='d7VDF'></small><noframes id='d7VDF'>

                      • <bdo id='d7VDF'></bdo><ul id='d7VDF'></ul>

                      <i id='d7VDF'><tr id='d7VDF'><dt id='d7VDF'><q id='d7VDF'><span id='d7VDF'><b id='d7VDF'><form id='d7VDF'><ins id='d7VDF'></ins><ul id='d7VDF'></ul><sub id='d7VDF'></sub></form><legend id='d7VDF'></legend><bdo id='d7VDF'><pre id='d7VDF'><center id='d7VDF'></center></pre></bdo></b><th id='d7VDF'></th></span></q></dt></tr></i><div id='d7VDF'><tfoot id='d7VDF'></tfoot><dl id='d7VDF'><fieldset id='d7VDF'></fieldset></dl></div>