My view model became very large, so I decided to split it into several files. I have already tried many different approaches, but nothing worked.
My model looks like this:
namespace.model = function(constructorParam) { var self = this; self.param1 = ko.observable(constructorParam.param1); self.param2 = ko.observable(privateFunction(constructorParam)); self.clickEvent = function() {
I need to access private functions and observable parameters in multiple files. My latest model should look like this:
// file 1 // contains constructor and param initialization + many common private helper funcitons namespace.model = function(constructorParam) { var self = this; self.param1 = ko.observable(constructorParam.param1); self.param2 = ko.observable(privateFunction(constructorParam)); function privateFunction(param) { // do some stuff } function privateFunction2(param) { // do some stuff } }; // file 2 // contains event hendlers self.clickEvent = function () { // i need to acces properties from namespace.model self.param1 // call some private funcitons privateFunction2(self.param2); }; // view model initialization ko.applyBindings(new namespace.model(initValues));
Is it possible to achieve something similar with a knockout? thanks
Marian ban
source share