KnockoutJS, updating ViewModel after ajax call

前端 未结 2 1412
[愿得一人]
[愿得一人] 2021-01-31 23:04

I am using Knockout and the Knockout Mapping plugin.

  • My MVC3 Action returns a View and not JSON directly as such I convert my Model into JSON.
  • This is a d
2条回答
  •  天涯浪人
    2021-01-31 23:44

    Should't you use ko.mapping.updateFromJSON on your success event? Chapter Working with JSON strings on Knockout Mapping site says:

    If your Ajax call returns a JSON string (and does not deserialize it into a JavaScript object), then you can use the functions ko.mapping.fromJSON and ko.mapping.updateFromJSON to create and update your view model instead.

提交回复
热议问题