-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Having more models in a viewmodel when using "factories" #153
Comments
Glad to hear you've enjoying it. Hmmmm. If there was a single model with both apples and a pear, and you configured the reverse relationships for each, and you could traverse the model relationships from apple to apples then to pear when passed in.
Would that work? |
Thank you for your quick response. Yes that would work but it would create an unwanted relation between the models. Apple(s) and the Pear model I mean. They don't really relate to each other on the model level. What I'm search for is for the viewmodel (AppleViewModel) to have access to the PearModel. Can this be done? |
Most of the time the combination of model relationships or traversing the $data stack in the view using Knockout cover most cases. I'm trying to think if there is a work around to pass the data through and the best I can think of is using a constructor for the view models. See create API examples like this and this. If you need this also for the model (non-collection) case, you can also look at the view model tests for create examples. Basically, you have the option to use a create function install of passing a reference to the view model constructor in the factory. Then you can create an instance of your view model and pass whatever parameters you want to the constructor. Would this work for you? |
Yes that is exactly what I was looking for! Thank you. |
Hey kmalakoff
I'm facing a problem while using your otherwise wonderful framework. In applesVM below I'm using "factories" to automate the creation of a new viewmodel, a AppleViewModel, when a new apple is added to the applesModel.apples Backbone collection. But the new AppleViewModel also needs access to the singleton instance of my pearModel. But I can't figure out how to inject this model into the new instances of my AppleViewModel. How do I do this in Knockback?
Kind regards Morten Larsson
The text was updated successfully, but these errors were encountered: