mercredi 7 septembre 2016

Ember.JS create record in component and add to local Datastore, or best practice solution

Current situation: I am trying to find a way to create a record of a specific model from within the "didInsertElement" method of a component, and add said data to the data store.

Reason for current situation: I am attaching event listeners to a button in my component HBS file. One of the buttons will trigger two cascaded but light ajax calls. The response from the last of these ajax calls will determine if I should create records or not.

Problem I am having: When I try to access the store like this from the component:

    var myStore = this.store

I am getting an undefined object. For those of you asking, I have already added the following line to my component:

    store: Ember.inject.service()

And I already have Ember-Data installed.

Solutions: I have found from a lot of research that interaction with the store is best done through the main route. But how would I attach event listeners to a component's jquery widget from a route?

Are there any solutions that wouldn't require me to move all all the event listener code from the component to the route and thereby undo the modularity that ember is supposed to offer?




Aucun commentaire:

Enregistrer un commentaire