Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
Cómo forzar el procesamiento después de una condición If en la etiqueta html en svelte

Esto es lo que tengo en el html de mi página:

 {#each subCategories as subCategories} {#key $cart} {($cart.indexOf(subCategories.name) > -1)} {#if ($cart.indexOf(subCategories.name) > -1)} Test {:else} <div class="media ali list-group-item list-group-item-action clique" on:click={() => changeCart(subCategories.name)}> <div class="media-left"> <Management/> </div> <div class="media-body" > <h4 class="media-heading">{subCategories.name}</h4> </div> </div> {/if} {/key} {/each}

para la parte js esto es lo que tengo:

 import { writable } from "svelte/store"; let cart = writable([]); function changeCart(subCat) { $cart.push(subCat); console.log($cart); }

Pero el problema es que la condición if no recarga/renderiza en otro momento y el cambio de caso funciona solo después de volver al componente anterior y volver a este componente en otro momento.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debido a que la reactividad de Svelte se activa mediante asignaciones, el uso de métodos de matriz como empujar y empalmar no generará actualizaciones automáticamente.

Fuente: https://svelte.dev/tutorial/updating-arrays-and-objects

Solución:

 import { writable } from 'svelte/store'; let cart = writable([]) function changeCart(subCat) { // $cart.push(subCat) $cart = [...$cart, subCat] console.log($cart) }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!