mercredi 5 juin 2019

Ember Data: Change model data in component and write it back to API

I'm learning ember.js right now and having trouble to understand how editing model data works. I have a simple model called singleitem:

export default Model.extend({
    test: DS.attr('string')
});

There's a template singleitem.hbs that uses a template component interface_text.hbs containing this line:

<input type="text" value="" />

And a corresponding interface_text.js component:

export default Component.extend({
    change() {
        console.log(this);
    }
});

Whenever I change the content of the <input> tag, the change() method fires, so this works. But how do I update the model with the new value of the <input>?

(My ultimate goal is to write the changed data back to my API. Using this.test.save(); initiates a PATCH request to my API, but sends back the unaltered data. So I think I have to change the model first.)




Aucun commentaire:

Enregistrer un commentaire