Wednesday 15 May 2013

javascript - Updating Knockout viewModel -


I am trying to update a beaten view model, but every time I push an observable array If I try, then it is an error to me that AuditViewModel is undefined. function (data, updates) {if (updated == incorrect) {var audit mode = {auditEvents: ko.observableArray (data.requirements)}; Ko.applyBindings (AuditViewModel); } And {auditViewModel.auditEvents.push (data.requirements); }}

On this page load, this function always runs with update == incorrect, and it basically populates the visual model. When I call with update == truth later, it fails. Can anyone point me in the right direction?

Note that the line var AuditViewModel = {...} only if updates == incorrect is run. Because AuditViewModel is a local variable, if you call later, when update == true , auditModel will be undefined.

You will need to store the visual model elsewhere, that is: window.AuditViewModel = {...} .

Example:

  function (data, updates) {if (update == false) {Window.AuditViewModel = {auditEvents: ko.observableArray (data.requirements)} ; Ko.applyBindings (window.AuditViewModel); } And (window: audit viewmodel.audit avenues.pash (data .requirements);}}    

No comments:

Post a Comment