marxsk
November 2, 2017, 11:07am
#1
I’m trying to find out if Ember.A() can be used also with non-Objects. In the documentation, ethe strings are used in Enumerables together with pushObject() [e.g. in https://guides.emberjs.com/v2.16.0/object-model/enumerables/ ]
But when I try to add an empty string (as with push()), the value is not added. When I try to do replace, the item is removed from the array.
let arr = Ember.A(['first', 'second', 'third']);
arr.replace(0, 1, 'new-first');
arr.replace(1, 1, '');
CezaryH
November 2, 2017, 1:07pm
#2
marxsk
November 2, 2017, 1:40pm
#3
Thanks, pushObject() works as expected that makes it inconsistent. Originally, I had code with pushObject but then I shortened it to array initialization.
I need to replace/remove items from inside the array, so push(pop)Object does not work for me that well.
marxsk
November 4, 2017, 1:26pm
#4
So, third parameter have to be collection. In later versions, you will see an assert that will warn you about it (thanks to Serabe and his PR#15814).
Solved.
Correct solution is:
arr.replace(1, 1, ['']);
1 Like