As I understand, $index is available inside a foreach: binding, giving the index of the object... I have a click: binding e.g. c
It is easier with ES6 code. In my html I have an array of pages
In the view controller class I have the gotoPage method. The first parameter will be the $index of the foreach. Very simple.
class ViewModel {
constructor() {
this.requestedPage = ko.observable(0);
this.pages = ko.observableArray([0,1,2,3]);
}
async run() {
this.message("Running");
}
gotoPage(pageRequested, event) {
this.requestedPage(pageRequested);
this.run();
}
}