javascript - Knockout cloning does not work with function instances -
Actually what I read and whatever used to clone the array without any reference between me It was something like this:
But in this it does not work: reference var clonedArray = ko.observableArray (original array). Piece (0));
var field = function (settings) {var _self = This; _self.Id = settings.Id; _self.flag = ko.observable (settings.Flag); Return _self; }; Var viewmodel = function () {var _vm = this; _vm.fields = ko.observableArray ([New field ({id: 1, flag: true}), new area ({id: 2, flag: wrong})]); _vm.fieldsCloned = ko.observableArray (_vm.fields (.) Piece (0)); Return _ VM; }; Ko.applyBindings (new viewmodel ());
answer
< P> I had to face the same task; There is only one reason for cloning an observable array, how can I understand this, a JS object is viewable, then convert that object into an objective object. The KnockoutJS mapping plugin is required for the following functions:
function clone observer object (return ko.mapping.fromJS (ko.toJS (observableObject)); }
Comments
Post a Comment