Add objects to an array property of the model from a component. DDAU


#1

Hi,

I have a component that gets passed the model Point

As per DDAU I want to add to an array of shots, which is a property of Point. I therefore need to obtain or pass in the point to the registerShot action in the route:

  actions: {
    registerShot(point, shot) {
      point.get('shots').addObject(shot);
    }
  }

inside my component: <button class="btn" {{action (route-action "registerShot" point "FH")}}>Forehand</button>

This doesn’t work and is perhaps conceptually unsound?

How would I go about this? Is there a way to get the model that is loaded by the route inside that route’s action?


#2

OK I solved it:

  actions: {
    registerShot(shot) {
      this.get('controller.model.shots').pushObject(shot);
      this.refresh();
    }
  }

<button class="btn" {{action (route-action "registerShot" "FH")}}>Forehand</button>