1

I have a array of quote items that created dynamically by user. By default there is an item in list. When I click on new item, a null object push to array. Until now every things is OK, but when I add 3rd record, 2nd and 3rd record confuse to each other and every things that change in 3rd record as real time apply to 2nd record. It's my sample code:

https://codepen.io/anon/pen/gXZLZy

This problem has raised after adding the deletion function

What should I do?

2 Answers 2

1

you are pushing a copy of the same object on the list - so you need to copy/clone it, otherwise it will just be a reference to the same object. This seems to be the easiest way to do so:

        this.quote_items.push(Vue.util.extend({}, this.newItem));
Sign up to request clarification or add additional context in comments.

1 Comment

I guess it's a duplicate of: stackoverflow.com/questions/30578254/…
0

My problem because of newItem variable that push to array. I change this code:

this.quote_items.push(this.newItem);

to

this.quote_items.push({
            inventory_id: '',
            count: 1,
            fee: 13500000,
            discount: 0,
            sum: 0,
            tax_percent: 9,
            tax_amount: 0,
            total: 0
        });

https://codepen.io/anon/pen/gXZLZy?editors=1010

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.