knockout.js - knockout recursive mapping issue -
This post is a follow up on this.
I have updated the following code:
viewModel.getQuotesSuccess = function (result) {var myCoverQuotesViewModel = function (data) {var itself = this; Ko.mapping.fromJS (data, {}, self); Self. Children = ko.observableArray (ko.utils.arrayMap (data.Childs, function (c) {new myCoverQuotesViewModel (c);})); Self.selectedChild = ko.observable (); Self. Showcill = ko.computed (function (selected) (self) selected hair () & self. Selected hair (). Hair (length) gt; 0;}); Var mapping = {'covercotes': {create: function (option) {new myCoverQuotesViewModel (options.data); }}} Ko.mapping.fromJS (Results, Mapping, View Modell); Label: 'test', hair: [{id: 2, label: 'child1'}]]}}; In short, I have an array of covercots, in which each element has an array of covercots (or so on).
I have a problem with this mapping, the child's observation array, when calling:
return myCoverQuotesViewModel (options.data); for the main object, it works fine. While calling the Consultant within the VS Sarfam function, then that line:
to.mapping.fr JS (data, {}, itself); As a result, nested children are assigned children and show children, but they are all remembering others (like this ID and label in the example). Mapping also works for children?
I have resolved my issue using recurring custom mapping viewModel.getQuotesSuccess = function (results) {var myCoverQuotesViewModel = function (data) {var itself = this; Var Mapping Kids = {'Childs': {create: function (new); myCoverQuotesViewModel (options.data); }}} Ko.mapping.fromJS (data, mapping child, self); Self.selectedChild = ko.observable (); Self. Showcill = ko.computed (function (selected) (self) selected hair () & self. Selected hair (). Hair (length) gt; 0;}); Self.isvisible = ko.computed ({read: function () {var visible = true; if (self.DependsOn (). Length> gt; {$ .each (self.DependsOn (), function (index, value ) {Var dependency = viewModel.QuoteSelectedViewModel (). CoverQuotes.filterByProperty ("code", value); if (Dependency (). Length> 0) {visible = visible and dependency () [0] .Isselected (); } Else {visible = false;}});} Return the visible;}, deferEvaluation: true}, this); } Var Mapping = {'CoverKotes': {create: function (new)); new myCoverQuotesViewModel (options.data); }}} Ko.mapping.fromJS (Results, Mapping, View Modell); };
Comments
Post a Comment