#Filtering with JSON
66 messages · Page 1 of 1 (latest)
oh, my bad
could you provide the code here?
it says its too long, is there any other way?
TypeScript extends JavaScript by adding types to the language. TypeScript speeds up your development experience by catching errors and providing fixes before you even run your code.
Preview:```ts
"use client"
import React, {useState} from "react"
import {Container} from "@/components/container"
import G3deon from "@/icons/G3deon"
import {
Avatar,
Badge,
Tooltip,
} from "@nextui-org/react"
import i18n from "@/locales/creditos.json"
import {Divider} from "@nextui-org/divider"
...```
oh, my plan was for it to get filtered depending on the teams (set on the arrays at the json), so if i clicked one team, it only shows the avatars of the members from that team
btw heres the json if that helps
yeah that might be helpfull
{
"HERO": {
"TITLE": "Créditos",
"DESCRIPTION": "En el Politécnico Madre Rafaela Ybarra, reconocemos y valoramos el esfuerzo y la dedicación de todas las personas que han contribuido al crecimiento y éxito de nuestra institución. Nuestra página de Créditos es un espacio dedicado a honrar y reconocer a aquellos que han dejado su huella en nuestra comunidad académica."
},
"MEMBERS": [
{
"ID": "daniel_rosario",
"NAME": "Daniel Rosario",
"AVATAR": "",
"TEAM": "FrontEnd"
},
{
"ID": "alexander_jimenez",
"NAME": "Alexander Jiménez",
"AVATAR": "",
"TEAM": "FrontEnd"
},
{
"ID": "katia_pujols",
"NAME": "Katia Pujols",
"AVATAR": "",
"TEAM": "FrontEnd"
},
{
"ID": "jarel_feliz",
"NAME": "Jarel Feliz",
"AVATAR": "",
"TEAM": "FrontEnd"
},
{
"ID": "adiel_santos",
"NAME": "Adiel Santos",
"AVATAR": "",
"TEAM": "BackEnd"
},
{
"ID": "aethan_franco",
"NAME": "Aethan Franco",
"AVATAR": "",
"TEAM": "BackEnd"
},
{
"ID": "nahuel_ramirez",
"NAME": "Nahuel Ramirez",
"AVATAR": "",
"TEAM": "BackEnd"
},
{
"ID": "jose_luis_almarante",
"NAME": "Jose Luis Almarante",
"AVATAR": "",
"TEAM": "Docente"
},
{
"ID": "pedro_reyes",
"NAME": "Pedro Reyes",
"AVATAR": "",
"TEAM": "Docente"
},
{
"ID": "juan_andres_moreno",
"NAME": "Juan Andres Moreno",
"AVATAR": "",
"TEAM": "Docente"
}
],
"TEAM": ["front-end", "back-end"]
}
sry its on spanish
thats no problem
but i think you get the team part
yep
i thought if i handled it with that value i could filter them
but doesnt seem to work neither way
so i assume selectedValue could be Docente or BackEnd etc
exactly
well
replace line 66 with
{i18n.MEMBERS.filter((member) => {return member.TEAM === selectedValue}).map((member) => (
ill try it, give me a moment
if this doesnt work try
{{i18n.MEMBERS.filter(member => member.TEAM == selectedValue).map((member) => (
tried both, they just take the avatars out and dont filter
ill provide pics on how it looks
no need to
oh alr
u sure this is all the code there is?
this is the only place where the list is processed
thats all the code that involves that page, yes
if theres another way to do it im also fine with it
okay maybe i need a display after all but could you insert a new line after line 139 <div>{member.ID}</div>
would be helpfull to understand whats going on
oh im sorry, i inserted your json to fix it
anyways i mean your original line 70
could you show me what happens with the adjustment of my first answer if you type in a team name?
kk
gimme a sec, my discord pc froze lol
for starters, it doent map the avatars as it did, and when i select nothing happens
makes sense because your filter is emtpy
to fix this just do this
{i18n.MEMBERS.filter((member) => {return (!selectedValue || selectedValue.length == 0) ? true : member.TEAM === selectedValue}).map((member) => (
it really just displays the same problem
same problem happened to me with other methods, same exact problem
im not really into the Webframeworks to much and dont know about the livecycles. But this would be the correct way to filter your json array in JS
Preview:ts let i18n = { HERO: { TITLE: "Créditos", DESCRIPTION: "En el Politécnico Madre Rafaela Ybarra, reconocem ...