Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Why this Svelte 5 condition object isn't working for this list?

$
0
0

In this reproduction I'm trying to understand if it's possible and if this is the idiomatic way to create a condition filter for a list merging variables from parents too...

But it doesn't work.

As you can see, when you open the project the condition is empty {}.

Instead I need it to be:

{"or": [    {"withPlayer": {"name": "testMe"      }    }  ]}

Is there a way?

App.svelte:

<script>    import List from "./List.svelte";</script><List searchText={"testMe"} />

List.svelte:

<script>    let {        pagination = { current: 1, size: 5 },        condition = {},        searchText    } = $props();    const facade = {        get searchText() {            return searchText        },        set searchText(value) {            searchText = value;            condition.or = (condition.or || []).filter((item) => !item.withPlayer);            if (value) {                condition.or.push({ withPlayer: { name: value } });            }        }    }</script><input type="text" bind:value={facade.searchText} /><br><br>condition: <pre>{JSON.stringify(condition, null, 2)}</pre>

I can add facade.searchText = searchText; to the end of the script, but in this example I only have searchText but in real code I have many of them and is not easy to remember to add all of them at the end of the script when I add or remove props.

Any idea?


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>