Compress CODE

Hello everybody,

i am working on a filter-engine and i have some troubles to compress my code, to get it more flexible and dynamic.

Here is the related part of the engine-code…

//example-structure......
var REFERENCE1  = "value1"        ;   
var REFERENCE2  = "value2"        ;   
var REFERENCE3  = "value3"        ;    
var REFERENCE4  = "value4"        ;   
var REFERENCE5  = "value5"        ;   
var REFERENCE6  = ""              ;  
var REFERENCE7  = ""              ;  
var REFERENCE8  = ""              ;    
var REFERENCE9  = ""              ;   
var REFERENCE10 = ""              ;   

//----[ REF1 - REF-10 ] - DropDowns ------------------------------------------------------
refFields = [REFERENCE1, REFERENCE2, REFERENCE3, REFERENCE4, REFERENCE5]
//MEMdropdowns   =  [MEMref1, MEMref2, MEMref3, MEMref4, MEMref5]
//----[ REF11 - REF-20 ] - CBoxes --------------------------------------------------------
refCBoxes = [REFERENCE11, REFERENCE12]

async function uniqueTitles_DropDowns (parameter) {
 let loadedDatabase = wixData.query(DATABASE)
 let Options = []

 for (var a = 0; a < refFields.length; a++) {
 let myCHBarray = [refFields[0], refFields[1], refFields[2], refFields[3], refFields[4]]
 await loadedDatabase.distinct(myCHBarray[a])
        .then(async(results) => {
 if (results.items.length > 0) {
 let items = results.items;
 
 for (var b = 0; b <items.length; b++) {//console.log(items[b])      
                    Options.push([])    
                    Options[a].push({"label": items[b], "value": items[b]})
                }   
                console.log(Options[a]) 
                $w('#DD'+(a+1)).options = await Options[a]
            }
        })
    }
}

I have marked, what i want to be compressed in the CODE.

I need it in this way…(which do not really work.

[refFields[a]]

How to put this into a LOOP???

let myCHBarray = [refFields[0], refFields[1], refFields[2], refFields[3], refFields[4]]

Pursued goal should be something like this…

for (var a = 0; a < refFields.length; a++) {
    let myCHBarray = [refFields[a]]
}

Using this version…(inside a loop)

let myCHBarray = [refFields[0], refFields[1], refFields[2], refFields[3], refFields[4]]

…everything works just fine.

Trying to compress and use this one… (inside a loop)

let myCHBarray = [refFields[a]]


The first loop works and then breaks down. :sleepy:

Here is the example-Filter-Engine…
https://www.media-junkie.com/pflegeservice

Why are you putting refFields[a] inside an array?

My aim is to control everything just from here…

var REFERENCE1  = "value1"        ;   
var REFERENCE2  = "value2"        ;   
var REFERENCE3  = "value3"        ;    
var REFERENCE4  = "value4"        ;   
var REFERENCE5  = "value5"        ;   
var REFERENCE6  = ""              ;  
var REFERENCE7  = ""              ;  
var REFERENCE8  = ""              ;    
var REFERENCE9  = ""              ;   
var REFERENCE10 = ""              ;   

You put a new value —> and it works.
All the code-actions should then adapt the new value.

But i do not really have had any luck, to get it to work like i want.

The Search-Engine works at all, but is not flexible enough to control just with one line.

This part here…

async function uniqueTitles_DropDowns (parameter) {
 let loadedDatabase = wixData.query(DATABASE)
 let Options = []

 for (var a = 0; a < refFields.length; a++) {
 let myCHBarray = [refFields[0], refFields[1], refFields[2], refFields[3], refFields[4]]
 await loadedDatabase.distinct(myCHBarray[a])
        .then(async(results) => {
 if (results.items.length > 0) {
 let items = results.items;
 
 for (var b = 0; b <items.length; b++) {//console.log(items[b])      
                    Options.push([])    
                    Options[a].push({"label": items[b], "value": items[b]})
                }   
                console.log(Options[a]) 
                $w('#DD'+(a+1)).options = await Options[a]
            }
        })
    }
}

Gets all the unique values of each Dropdowns.
I want the code to be able to recognize AUTOMATIC, how much VALUES are active in the USER-INTERFACE…

USER-INTERFACE—>

var REFERENCE1  = "value1"        ;   
var REFERENCE2  = "value2"        ;   
var REFERENCE3  = "value3"        ;    
var REFERENCE4  = "value4"        ;   
var REFERENCE5  = "value5"        ;   
var REFERENCE6  = ""              ;  
var REFERENCE7  = ""              ;  
var REFERENCE8  = ""              ;    
var REFERENCE9  = ""              ;   
var REFERENCE10 = ""              ;   

Recognizing the length of —> refFields —> like in this example —> ( 5-active-values )
with a loop…

for (var a = 0; a < refFields.length; a++) {

}

This codeline is my problem…

let myCHBarray = [refFields[0], refFields[1], refFields[2], refFields[3], refFields[4]

How to convert (to transform it) into …

let myCHBarray = [refFields[a]] 

… so that the active refFields are found automatic and just all the active DropDowns are filled with unique titles.

Why are you putting refFields[a] inside an array?
I think i got you.

Let me try to change something.

OKEEEEYYYYYY J.D.! THANKS! I got it! I understood your message. :grin:

:slight_smile: You’re welcome