0

We have this data structure

[[{foo:"12", bar:"34"}, {foo:"33", bar:"55"}], [{foo:"45", bar:"67"}]]

How is it possible to make a computed property to observe a change on foo or bar?

2
  • It depends on what you need to cover. What about array[0][0] = {foo:"89", bar:"01"} would that constitute as a change? Commented Oct 9, 2019 at 13:51
  • The objects in the arrays dont get overwritten, only their properties change or objects are added. Commented Oct 9, 2019 at 13:56

1 Answer 1

1

Normally you use [email protected] in a computed property to watch specific object properties in an array but in the case of nested arrays (or nested objects), you can't do .@[email protected] because .@each only works one level deep.

You need to use intermediary computed properties to raise the inner objects up one (or more) levels and have another computed property watch these in turn. There may be other ways to wire things up, but this is a pretty straightforward way to do it.

Here's a twiddle that demonstrates it. If you open the console you can see the individual computed properties recording a change occurring.

You can also use an alias to pull the inner arrays / objects up a level or two.

Sign up to request clarification or add additional context in comments.

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.