0

How to push same element observable array without any reference b/w old and new element?

To add multiple category with diff sub-category

enter image description here

As you can see in above When I am Click on “+” button, new element is pushed in array and after that trying to Change “New” in sub-Category for second row, it;’s auto-changed in first row also.

Prasad Khode
  • 6,602
  • 11
  • 44
  • 59
Manveer Singh
  • 351
  • 6
  • 27
  • Clone the object before adding it. Using `var objToPush = ko.toJS(ko.fromJS(existingObj));` – haim770 Jun 16 '16 at 07:04
  • Check out the answers here: http://stackoverflow.com/questions/12333915/how-do-i-make-a-deep-copy-of-a-knockout-object-that-was-created-by-the-mapping-p – user3297291 Jun 16 '16 at 07:43
  • Thanks, Above code working fine in case of Parent Items, but in case of it's child items (category), same issue is occurring. – Manveer Singh Jun 16 '16 at 10:27
  • @haim770 can you help me for same also. – Manveer Singh Jun 16 '16 at 10:30
  • You probably need to deep-clone. See http://stackoverflow.com/questions/12333915/how-do-i-make-a-deep-copy-of-a-knockout-object-that-was-created-by-the-mapping-p – haim770 Jun 16 '16 at 10:32

0 Answers0