0
var mapping = {  
'observe': ["testProperty"]  
}  
var viewModel = ko.mapping.fromJSON(data, mapping);  

But this is making all the properties in the viewModel as observable.

  • 1
    As far as I know observable properties are mapped to UI elements so that they are always in sync with eachother. So why would want to exclude a property from becoming a observable ? – dreamweiver Feb 16 '15 at 09:51
  • For example Model has 10 properties. From those properties i want to use 6 properties as textBox fields and 4 properties as readonly fields. So, I want to make 6 properties as observables and 4 properties as unobservable in my ViewModel. – Bharat Cheparthi Feb 16 '15 at 11:51
  • even for certain properties to appear within a readonly field dont you think there should be some binding b/w properties & UI fields(readonly ) ? what seems like a better approach to me, is to make use of 'Enable' binding. – dreamweiver Feb 16 '15 at 13:38

1 Answers1

2

Yes we can do this by using copy which is straight from Ko Doc's here Ignoring certain properties being observables using “copy”

If you want the mapping plugin to simply copy the plain properties and not make them observable, use this argument, as shown below.

// tell the mapping plugin to handle all other properties normally, but to simply copy this property instead of making it observable

    var mapping = {
        'copy': ["propertyToCopy"]
    }
    var viewModel = ko.mapping.fromJS(data, mapping);

I suggest you to go through this wonderful post here

Working fiddle here explaining the case

Community
  • 1
  • 1
super cool
  • 6,003
  • 2
  • 30
  • 63