I've started exploring KnockoutJS just to see if i can use it with my ASP.NET MVC app. and there are many gray areas that i'm trying to figure out. I must admit its more because of my poor understanding regarding JSON in general and if i'm not wrong then it might also be because of the ASP.NET JSON format in particular or I'm totally wrong either way i need the answers.
I just want to know How to replicate data model that ASP.NET MVC returns via $.get. via JavaScript model.
- one simple objects
- nested/complex objects
Code:
list = ko.observableArray([]);
ko.applyBindings(list);
function loadTeamMembers(projectId) {
$.ajax({
type: "GET",
url: "/Project/GetTeamMembers?projectId=" + projectId,
success: function (data) {
$(data).each(function (index, item) {
list.push(item);
});
}
});
}
loadTeamMembers(6);
I used the code above on my table where I have data-bound this with the Knockout list (which works). What about adding/deleting new items to/from the list? I expect I would need a JavaScript model on the client side. How exactly should I create the JavaScript model (looking for two aforementioned examples) on the client so it works with ASP.NET MVC JSON data?
Any info or links will be much appreciated.