0
votes

Protected observable requires parameters passed to the function e.g. :

var item = function(param)
{
  var me = this;
  me.itemProtected = ko.protectedObservable(param);

}

I don't know inner workings of the KO mapping plugin, but if I use it to map Json data to my model protected observable will not work. I assume it is mapping properties only as observables and ignoring protected observables altogether. The binding syntax:

ko.mapping.fromJSON(data, null, viewModel);

Is there a way to map json data and preserve protected observable?

Your help will be much appreciated.

1

1 Answers

1
votes
ViewModel = function(data)
{
   this.itemProtected = ko.protectedObservable();
   return ko.mapping.fromJS(data, {}, this);

}

The JSON data offcourse need to have a member called itemProtected for this to work

edit: Disclamer, I do not know what a protectedObservable is and its not part of the core KO library.

edit: