0👍
✅
Full Answer:
The problem with the code is that you are using the item index within function ‘changeDefault’, you should instead use the name of the item, because the index is dynamic, so if you search for ‘Text 2’, the index that would be used is 0, and not 1:
function changeDefault(clickedItem) {
let indexOfDefaultTrue = items.findIndex((item) => item.default === true);
let indexOfbuttonClicked = items.findIndex((item) => item.name === clickedItem.name);
items[indexOfDefaultTrue].default = false;
items[indexOfbuttonClicked].default = true;
}
And the input radio:
<input
type="radio"
:checked="item.default"
@click="changeDefault(item)"
/>
1👍
It sounds like ‘filteredItems’ is not reactive, is it a computed function? As it sounds like it’s not rerunning every time ‘this.search’ is changing.
If you have a larger example of the code, I can take a look.
Source:stackexchange.com