Currently, I am delving into the world of knockout.js and finding it quite challenging to figure out how to create nested complex types within it.
For instance, in my backend model, I have defined:
class Person {
public string Name {get; set;}
public int Age {get; set;}
public List<Colors> FavoriteColors {get; set;}
}
class Color {
public int ColorId {get; set;}
public string Name {get; set;}
}
When asp.net mvc outputs JSON for a List<Person>
type, it looks something like this:
[{"Name":"JC","Age":24,"Colors":[{"ColorId":1,"Name":"Red"},{"ColorId":2,"Name":"Blue"}]},
{"Name":"Albert","Age":29,"Colors":{"ColorId":2,"Name":"Blue"}}]
My goal now is to map this data using observables fetched through Jquery Ajax. While I understand that FavoriteColors
will be an array, I'm uncertain about how to proceed...
I would greatly appreciate any guidance on this!
UPDATE:
Is there anyone who can assist me with this issue? (I attempted a prototype, but encountered issues with my select functionality)