Need help with syntax during list filtering

I have a list of clothing items and a variable [gender] that contains value for example "♂️" male. Some items on the list of clothing also contain emojis ♀️ or ♂️ in them, something like "Batman suit♂️". I'm trying to exclude all items with ♀️ if "gender==♂️" and vice versa. I've tried to use clothingTop.selectAll.filter(newlist =>newlist.tags.includes([gender])), ald also match(/♀️/i), I'm not sure how to proceed.

3 points · 10 comments · view on lemmy.world

10 Comments

VioneT@lemmy.world · 2 pts · 1y (9 replies)

Can you send the generator link?

For clothingTop.selectAll.filter(newlist =>newlist.tags.includes([gender])) you don't need to enclose gender in a square bracket. Also, if the tags are a list. you might also need to .selectAll to turn them into an array; if in text I think it should work.

Koto@lemmy.world · 1 pts · 1y (8 replies)

it's a mess of a text to go through but here it is https://perchance.org/imageconstructor basically, you would want to find "[clothingList.Top.joinItems('<\option>')]" in the html part where I put this list as options into the select form.

VioneT@lemmy.world · 1 pts · 1y (7 replies)

Something like this worked:

clothingList.Top.selectAll.map(a => a.getName).filter(a => gender.includes('♀️') ? !a.includes('♂️') : !a.includes('♀️')).joinItems('<\option>')
  • .map(a => a.getName) - returns the name of the item, and not the item under it, and not a list since .selectAll returns an object and not a string.
  • filter(a => gender.includes('♀️') ? !a.includes('♂️') : !a.includes('♀️') - checks if the gender is female, if so, then filter out the items with ♂️ (!a.includes('♂️') essentially says if the name doesn't have♂️, then return it), else filter out items with ♀️

Also I'd recommend using $output on the list, so you just have to call clothingList.Top like so:

clothingList // clothing top, bottom, footwear, headwear, accessories, color, pattern
  Top
    $output = [this.selectAll.map(a => a.getName).filter(a => gender.includes('♀️') ? !a.includes('♂️') : !a.includes('♀️')).map(a => `<option value=${this[a]}>${a}</option>`).join('')]
    ---
    Any
    None
    Bikini top♀️
      bikini top
    Blouse♀️
      blouse

Koto@lemmy.world · 1 pts · 1y (5 replies)

Thanks for the detailed explanations. I'm getting this error: "An error has occurred somewhere in your code (in lists or HTML): There's a problem with the syntax of this expression: '[clothingList.Top.selectAll.map(a => a.getName).filter(a => gender.includes('♀️') ? !a.includes('♂️') : !a.includes('♀️')).joinItems('<\option>')]'. Here's the message that was returned when execution failed: Cannot read properties of undefined (reading 'includes').

VioneT@lemmy.world · 1 pts · 1y (4 replies)

On my end, there doesn't seem to be any problems? What method are you using, directly on the HTML, the $output method, or both? If both, then there might be a problem.

Koto@lemmy.world · 1 pts · 1y (2 replies)

How do I work with $output now in the list section to call an individual item from the list? I used to do it like this [clothingList[clothingGroup][clothingTop].joinItems(", ")] where clothingGroup is the html optgroup and clothingTop is the name of the item('this.value'). ${clothingTop[clothingGroup][clothingTop]} or clothingList[clothingGroup][clothingTop] returns undefined. Sorry for the noob question, as you can tell I'm new at this :-)

VioneT@lemmy.world · 2 pts · 1y (1 reply)

I forgot to enclose the value=${this[a]} with quotations, so that is one problem. You can remove the value of the option if you are using the value to access back the list like so:

$output = [this.selectAll.map(a => a.getName).filter(a => gender.includes('♀️') ? !a.includes('♂️') : !a.includes('♀️')).map(a => `<option>${a}</option>`).join('')]

So that clothingTop will return the list name e.g. Dress♀️, then using it with [clothingList[clothingGroup][clothingTop]] should return the item below it i.e. evening dress with deep neckline.

Setting the value to this[a] would have the value of the option set directly to evening dress with deep neckline and not Dress♀️ so [clothingList[clothingGroup][clothingTop]] would not work, but you can access the value directly with clothingTop.

Koto@lemmy.world · 1 pts · 1y

Yeah that works, much appreciated! I noticed that the value was different from the name, it was lowerCase and no emoji that's why I couldn't call it.

Koto@lemmy.world · 1 pts · 1y

I put [clothingList.Top] in the HTML and $output line in the lists and it works. I just need to change the item references now in the lists itself. clothingList.Top[clothingGroup][clothingTop].joinItems(", ") doesn't work anymore since there are no items inside to join.

Koto@lemmy.world · 1 pts · 1y

Just what I wanted with the $output. Much appreciated, works like wonders!