I have a ko.observableArray and I’ve added a subscriber for items in the observable array:
eventDate.subscribe(function(newDate) { ... }
Within that handler, I have no access to the parent or root of my view model.
When I access this, I get a reference to window. What I would like to do is get access to the scope which contains the observable array. (I have tried normal and fat arrow => in coffeescript for scope).
My reasoning is that I have data that I didn’t want duplicated/referenced within the observable array for each item. I mostly have experience with backbone, so perhaps this is not the “knockout.js” way.
My goal is to have ko.applyBindings new MainModel() instead of adding a reference for my model in window.
I’ve created a jsfiddle to demonstrate:
http://jsfiddle.net/brianzinn/r4bd8/
Thanks. Does anybody know a solution?
Edit
Passing the view model in the constructor gives access to the parent, is this a good practice?
http://jsfiddle.net/brianzinn/r4bd8/7/
What you should do is pass the parent down through the
Rowconstructor. Then you will have easy access to the Row’s parent.It would look something like:
Then you can access
parentfrom within theRow.Constructing the Row would change slightly too: