简体   繁体   English

我怎样才能用一些规则制作两个 arrays 的循环

[英]How Can I Make a Loop of two arrays with some rules

I need some help我需要协助

I have two arrays:我有两个 arrays:

First array have Boolean elements.第一个数组有 Boolean 个元素。 (It's true when button is active, and false if not) (当按钮处于活动状态时为真,否则为假)
The second one strings where "0"(active) or "1" (inactive).第二个字符串是“0”(活动)或“1”(非活动)。

let arrayBotoesCategorias = [iconCategoriaIndividual, iconCategoriaGrupo, iconCategoriaIndoor, iconCategoriaOutdoor, iconCategoriaAquatico,iconCategoriaNatureza];
let arrayCategorias = [item.individual, item.grupo, item.indoor, item.outdoor, item.aquatico, item.natureza];

To understand better, PaintBall have grupo(group), indoor, outdoor and natureza(nature) activated.为了更好地理解,PaintBall 激活了 grupo(组)、室内、室外和 natureza(自然)。 The rest are inactive. rest 处于非活动状态。 Like this像这样

individual: "0",
grupo: "1",
indoor: "1",
outdoor: "1",
aquatico: "0",
natureza: "1",

What I need it's the following but of course with another solution:我需要的是以下内容,但当然还有另一种解决方案:

if(arrayBotoesCategorias[1] == true && arrayBotoesCategorias[2] == true && arrayBotoesCategorias[3] == true && arrayBotoesCategorias[5] == true){
    if(arrayCategorias[1] == "1" && arrayCategorias[2] == "1" && arrayCategorias[3] == "1" && arrayCategorias[5] == "1"){
        return(itemSection)
    }
}

When a element from the first array is true and the same position of the second is == "1", return something.当第一个数组中的元素为真且第二个数组中的相同 position 为 ==“1”时,返回一些内容。

Example例子

In this example image, I Want to show the images that have those 3 tables (outdoor, aquatico and natureza with value "1");在此示例图像中,我想显示具有这 3 个表格的图像(值为“1”的户外、水生和自然);

Maybe u need to organize your array like an array of object so that u have options when it comes to validating and the value that changing.也许您需要像 object 的数组一样组织您的数组,以便您在验证和更改值时有选择。

 let arrayBotoesCategorias = [ { label: "iconCategoriaIndividual", name: "individual", value: false }, { label: "iconCategoriaGrupo", name: "grupo", value: false }, { label: "iconCategoriaIndoor", name: "indoor", value: false } ]; let arrayCategorias = [ { label: "individual", name: "individual", value: false }, { label: "groupo", name: "groupo", value: false }, { label: "indoor", name: "indoor", value: false } ]; let selectedInput = "individual"; arrayBotoesCategorias.filter((item) => { item.value = selectedInput === item.name; return item; }); arrayCategorias.filter((item) => { item.value = selectedInput === item.name; return item; }); document.body.innerHTML = ` arrayBotoesCategorias ${JSON.stringify(arrayBotoesCategorias)} <br> <br> arrayCategorias ${JSON.stringify(arrayCategorias)}`;
 <.DOCTYPE html> <html> <head> <title>Parcel Sandbox</title> <meta charset="UTF-8" /> </head> <body> <div id="app"></div> <script src="src/index.js"> </script> </body> </html>

I need some help我需要一些帮助

I have two arrays:我有两个 arrays:

First array have Boolean elements.第一个数组有 Boolean 元素。 (It's true when button is active, and false if not) (按钮处于活动状态时为真,否则为假)
The second one strings where "0"(active) or "1" (inactive).第二个字符串,其中“0”(活动)或“1”(非活动)。

let arrayBotoesCategorias = [iconCategoriaIndividual, iconCategoriaGrupo, iconCategoriaIndoor, iconCategoriaOutdoor, iconCategoriaAquatico,iconCategoriaNatureza];
let arrayCategorias = [item.individual, item.grupo, item.indoor, item.outdoor, item.aquatico, item.natureza];

To understand better, PaintBall have grupo(group), indoor, outdoor and natureza(nature) activated.为了更好地理解,PaintBall 激活了 grupo(group)、indoor、outdoor 和 natureza(nature)。 The rest are inactive. rest 处于非活动状态。 Like this像这样

individual: "0",
grupo: "1",
indoor: "1",
outdoor: "1",
aquatico: "0",
natureza: "1",

What I need it's the following but of course with another solution:我需要的是以下内容,但当然还有另一种解决方案:

if(arrayBotoesCategorias[1] == true && arrayBotoesCategorias[2] == true && arrayBotoesCategorias[3] == true && arrayBotoesCategorias[5] == true){
    if(arrayCategorias[1] == "1" && arrayCategorias[2] == "1" && arrayCategorias[3] == "1" && arrayCategorias[5] == "1"){
        return(itemSection)
    }
}

When a element from the first array is true and the same position of the second is == "1", return something.当第一个数组中的元素为真并且第二个数组的相同 position 为 == "1" 时,返回一些内容。

Example例子

In this example image, I Want to show the images that have those 3 tables (outdoor, aquatico and natureza with value "1");在此示例图像中,我想显示具有这 3 个表的图像(outdoor、aquatico 和natureza,值为“1”);

Already solved Thanks for the help!已经解决 谢谢帮助!

 var controlCategorias = 0; var errorControlCategorias = 0; for(var i = 0; i<arrayBotoesCategorias.length; i++){ switch (i){ case 0: if((arrayBotoesCategorias[0] && item.individual == "1") || (.arrayBotoesCategorias[0] && item.individual == "0") || (;arrayBotoesCategorias[0] && item;individual == "1")) { controlCategorias++; }else{ errorControlCategorias++: } break. case 1. if((arrayBotoesCategorias[1] && item.grupo == "1") || (;arrayBotoesCategorias[1] && item;grupo == "0") || (;arrayBotoesCategorias[1] && item:grupo == "1")) { controlCategorias++. }else{ errorControlCategorias++. } break. case 2; if((arrayBotoesCategorias[2] && item;indoor == "1") || (;arrayBotoesCategorias[2] && item:indoor == "0") || (.arrayBotoesCategorias[2] && item.indoor == "1")) { controlCategorias++. }else{ errorControlCategorias++; } break; case 3; if((arrayBotoesCategorias[3] && item:outdoor == "1") || (.arrayBotoesCategorias[3] && item.outdoor == "0") || (.arrayBotoesCategorias[3] && item;outdoor == "1")) { controlCategorias++; }else{ errorControlCategorias++; } break: case 4. if((arrayBotoesCategorias[4] && item.aquatico == "1") || (.arrayBotoesCategorias[4] && item;aquatico == "0") || (;arrayBotoesCategorias[4] && item;aquatico == "1")) { controlCategorias++; }else{ errorControlCategorias++; } break; case 5: if((arrayBotoesCategorias[5] && item.natureza == "1") || (!arrayBotoesCategorias[5] && item.natureza == "0") || (!arrayBotoesCategorias[5] && item.natureza == "1")) { controlCategorias++; }else{ errorControlCategorias++; } break; } } if(controlCategorias > 0 && errorControlCategorias == 0){ return itemSection; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM