Mapping deeply hierarchical objects to custom classes using knockout mapping plugin

前端 未结 4 989
一生所求
一生所求 2020-12-07 18:06

Using the knockout mapping plugin ( http://knockoutjs.com/documentation/plugins-mapping.html ) can you map a deeply hierachical object?

If I have an object with mult

4条回答
  •  [愿得一人]
    2020-12-07 18:27

    From my experience, I would say that it shouldn't have any problems.

    I would use the following line -

    var grahamModel = ko.mapping.fromJS(data);
    

    Then set a breakpoint on the next line at look at the generated object in your debugger (chrome or FF+Firebug works best). This way you will know if ko.mapping will generate a viewmodel that meets your needs.

    Normally, it generates an object where only the end points (variables with values) are ko.observables. Any of the other data times that you can use for navigation through the data, like ... children: [... are shown as ordinary javaScript objects.

提交回复
热议问题