Issue filtering a vector #615
Replies: 2 comments
-
Just a quick update I tested using a vector of tuples The tuple resulted in the same outcome as the vector of structs, but the vector of strings worked as expected. |
Beta Was this translation helpful? Give feedback.
-
Another update I was able to achieve the desired outcome with two different implementations that did not use First alternative is to use One caveat though is that I had to let action_options: Vec<ComboBoxOptions> = vec![]; // source data
let query: &Signal<String> = create_signal(context, String::new());
let options: &Signal<Vec<ComboBoxOption>> = create_signal(context, vec![]);
create_effect(context, move || {
let query = query.get().trim().to_lowercase();
options.modify().clear(); // this is required
options.set(
action_options
.iter()
.cloned()
.filter(|option| option.display_text.to_lowercase().contains(&query))
.collect::<Vec<_>>(),
);
}); Second alternative that works is just using the html input binding input(bind:value=query, type="text",
on:keydown=move |_: Event| {
let query = query.get().trim().to_lowercase();
options.modify().clear(); // this is required
options.set(
action_options
.iter()
.cloned()
.filter(|option| option.display_text.to_lowercase().contains(&query))
.collect::<Vec<_>>()
);
}) {} |
Beta Was this translation helpful? Give feedback.
-
Issue filtering a vector
Context
sycamore = { version = "0.8.2" }
perseus = { version = "0.4.2" }
Goal
I am trying to create a combobox basically.
I have one HTML
input
for the user to enter a search query/text and one HTMLselect
withoptions
built using a vector of structs.Ideally it should filter the vector of options in the combobox based on the search text.
I have tried implementing this a couple different ways, but the main issue I am having is that the rendered list of
options
doesn't update properly when the filter is applied usingcreate_memo
.Instead, the resulting list only contains the last item in the vector regardless of the search query.
I followed the
todomvc
example and tried using bothSignal<Vec<RcSignal<ComboBoxOption>>>
as well asRcSignal<Vec<RcSignal<ComboBoxOption>>>
and didn't see any difference in the output.I've looked at several different threads that I thought looked similar but just didn't find anything that solved my issue.
Any insight would be appreciated. Thanks!
Code Snippets
Beta Was this translation helpful? Give feedback.
All reactions