This post is just for documentation purposes. We have often a requirement to obtain the binding context instance of the DOM element.
This is usually the case when you for example subscribe some event. Following sample shows a keyup event as a INPUT element which is a child of some DIV element.
The parent DIV of clicked INPUT element holds the binding context.
$("input[data-iscontentchange='true']").keyup(function (e){
var clickedParentElement = $(e.originalEvent.target).parents()[0];
ko.contextFor(clickedParentElement).$data.IsConfigSettingDirty(true);
});
The ko.contextFor(clickedParentElement).$data holds the instance of the object which is bound to parent element.
Posted
Mar 06 2014, 11:25 AM
by
Damir Dobric