In other MVVM API’s for other frameworks, for example Caliburn Micro for WPF you can sub class view models. As an example I have this view model
Customer
Id : int
Selected : bool
Name : string
Edit : ViewModel
Depending on different Customer types I will have different Edit ViewModels, in Caliburn micro it would have automaticly rendered the correct view depending on the type of the ViewMOdel, types are offcourse not present in JS, but can you achive this some way in Knockout?
Thanks Mike, your solution is not exactly what I needed, Im doing something similar server side though, but our json-objects are read from a CQRS read model repository.
It turns out that named templates was what I was after.. Heres a little fiddle that shows what i did (In our real scenario the properties of the submodel will be on the actual customer object)
http://jsfiddle.net/Z7gMN/1/
Update:
Just saw that this answer got upvoted. There are more elegant ways of doing it, for example use my Convention over configuration library found here
https://github.com/AndersMalmgren/Knockout.BindingConventions
It has a convention for templates that uses the type so use a OO pattern of your liking like this one
http://ejohn.org/blog/simple-javascript-inheritance/
Define the different types, important is that they are postfixed with Model or ViewModel
The templates should have the same name but postfixed View
http://jsfiddle.net/JKXaX/5