I have an array object that is passed to my component and avalaible through @props.

console.log ( @props.users.pages )
> [ ["Tada", "A"], ["Todo", "B"] ] 

Actually, I want to append something to it (a new array).

What do you recommend beside this:

function add(){
  var arr = Array();
  arr.push("Toto", "C");
  @props.users.pages.push( arr );
  @forceUpdate()
}

The result after calling add() should be:

console.log ( @props.users.pages )
> [ ["Tada", "A"], ["Todo", "B"], ["Toto", "C" ] 

The biggest problem here is that arr can be destroyed by the garbage collector since it's only local and I would prefer to use @setProps instead of forcing updates manually.

没有正确的解决方案

其他提示

Remember what's the doc says:

So far, each component has rendered itself once based on its props. props are immutable: they are passed from the parent and are "owned" by the parent.

See it here Reactive state.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top