I am in the process of developing a TypeScript class that will handle all bindings using Knockout's mechanisms. Although I have made progress with the initial steps, I have encountered a roadblock. While I can successfully bind data to my HTML elements, I am struggling to manipulate them and trigger a refresh of the bindings.
Here is what I have implemented so far:
import * as ko from "knockout";
module Data {
export class Binder {
private _observableContext = ko.observable();
constructor() { ... }
public get ObservableContext() {
return this._observableContext ;
}
public set ObservableContext(value: any) {
this._observableContext = value;
}
public bind(elementID: string) {
ko.applyBindings(this._observableContext, $("#"+elementID));
}
}
}
This class is utilized as follows:
Class MyPage {
private _binder: Data.Binder;
public constructor() {
this._binder.ObservableContext({
data1: MethodA,
data2: SomeObject.GetData(),
...
});
this._binder.bind("someHtmlID");
}
public MethodA = () => {
// perform operations on the binder.ObservableContext() and update data
}
}
Despite trying various approaches, I have been unable to successfully refresh the bindings after modifying the _binder instance. The data within _binder is being updated correctly, but the changes are not reflected on the screen.
Any suggestions or solutions would be greatly appreciated!