So, I’m learning knockout.js and I am a bit stumped on how to create nested complex types in it.
For example, on my server-side, my model is:
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;}
}
The JSON that asp.net mvc outputs is something like (if I output a List<Person> type):
[{"Name":"JC","Age":24,"Colors":[{"ColorId":1,"Name":"Red"},{"ColorId":2,"Name":"Blue"}]},
{"Name":"Albert","Age":29,"Colors":{"ColorId":2,"Name":"Blue"}}]
Now I want to map that through observables, acquired through Jquery Ajax. I know that FavoriteColors would be an array, but I’m a bit confused how things would workout here…
Any help would be greatly appreciated!
UPDATE:
can anyone help me with this? (i made a prototype, but my select doesn’t work)
take a look at the knockout mapping plugin
edit: your sample edited: http://jsbin.com/eqihun/18/edit