Skip to content
Discussion options

You must be logged in to vote

For your given example, you could simply store the index of the toggled item in the message.

enum Message {
    ItemToggled(/*index*/usize, /*value*/bool),
}

The only thing that then needs to change in the view is to use enumerate() to extract the index from the iterator and store it in the message.

let col = self
            .items
            .iter()
            .enumerate()
            .fold(Column::new().spacing(10), |column, (index, item)| {
                column.push(Checkbox::new(
                    item.checked,
                    &item.name,
                    move |b| Message::ItemToggled(index, b),
                ))
            });

And then the index can be used in the upd…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@baileyn
Comment options

Answer selected by hecrj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #744 on February 23, 2021 00:14.