0👍
Looks like you need to use another variable to store the value for the selected index.
// Added variable selectedYearIndex
let selectedYearIndex;
getSelectedYearIndex() {
// Here I set the value of selectedYearIndex if it hasn't been been set yet
if (this.selectedYearIndex === undefined) {
this.selectedYearIndex = this.getYears.length - 1;
}
return this.selectedYearIndex;
}
Then you can set the value of the backing field
onSelect({ selectedIndex }) {
this.selectedYearIndex = selectedIndex
}
The reason that your assignment didn’t do anything is because this.getSelectedYearIndex = selectedIndex
is turning this.selectedYearIndex
into a number instead of assigning the value to a variable.
Source:stackexchange.com