I’m new to knockout js and got an observable array, when populating the array I subscribe on a property of each instance I’m adding, when the property changed (due to user interaction) I need to know which object changed, but knockout give me only the new value of the relevant property.
Is it possible to get the object? (I tried “this” in the function context without success)
length.isSelected.subscribe(function (isSelected) {
if (isSelected) { // no access to actual object only the isSelected value
debugger;
spotLenghts.push(this);
} else {
spotLenghts.pop(this);
}
});
The
subscribefunction takes a second argument that is thetarget. It will control whatthiswill be set to when your function is executed.So, you can potentially pass
length(or a higher level object that you are creating as appropriate) as the second argument and be able to usethisin your handler.