I started using knockout in my asp.net mvc 2 project
anyway i tried something simple. i created a model like so:
var userViewModel = {
ID: ko.observable(),
assignedGroups: ko.observableArray(),
avilableGroups: ko.observableArray(),
permissions: ko.observableArray()
};
then on the document.ready of jquery i called:
ko.applyBindings(userViewModel);
in the aspx itself i have:
<select multiple id="groupOfUser" class="multi_added_groups" data-bind="foreach: assignedGroups">
<option data-bind="text: $data, value: $data"></option>
</select>
<span data-bind="text: ID"></span>
if i first put data into userViewModel the view displays as expected. and that's great but i want the view to start off empty at first. then after the user chooses a user i make an ajax request my response is this:
{"ID":691,
"assignedGroups":["group1","group2"],
"avilableGroups":["role.administrator","role.editor"],
"permissions":[{"name":"admin","level":"ReadWrite"},
{"name":"admin.errorInfo","level":"Read"}]
}
then in my callback function:
ko.mapping.fromJS(res, userViewModel);
and that's it i guess. my view doesn't get refreshed with the new data from the server... what am i doing wrong?
thanks!