I have a custom composite widget that internally uses the MVVM framework for managing its data and behavior. I have the need to have the view model trigger events at the widget level so pages using the widget can monitor its changes.
What I'm having difficulty with is getting a reference to the widget from within its view model, so that I can call the trigger function. Is there a pattern for this?
My code looks roughly like:
What I'm having difficulty with is getting a reference to the widget from within its view model, so that I can call the trigger function. Is there a pattern for this?
My code looks roughly like:
MyWidget = Widget.extend {
viewModel: {}
init:
function
(element, options) {
this
.viewModel = initializeViewModel(
this
.options)
}
initializeViewModel:
function
(options) {
return
new
kendo.data.ObservableObject({
someFunctionThatNeedsAccessToTheWidget:
function
() {
// trigger event here
}
});
}
}