Adding properties to the view model created by using the Knockout JS mapping plugin

前端 未结 4 894
说谎
说谎 2020-12-02 13:41

I am working through the mapping plugin example on the Knockoutjs website.

This is the example data.

Knockout JS Mapping Plugin

var data = {
         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 13:49

    Note that to define additional computed observables on a child you will need to pass another set of mapping options

    var mapping = {
      create: function(options) {
        //customize at the root level.  
    
        var mapping2 = {
          'children': {
            create: function(options) {
              //customize children also
    
            }
          }
        }
    
        //call ko.mapping.fromJS on the options.data as well with further customization
        ko.mapping.fromJS(options.data, mapping2, this);
      }
    };
    

提交回复
热议问题