mercredi 14 septembre 2016

Updating record in an Ember Data record array

I need to update some of the data in my model, which happens to be a DS.RecordArray in this case, from the controller. My intention is to avoid having to do another API call to get the updated array after a save(). I am not sure what the best way to access specific elements of the RecordArray and modify them is.

I'm also not sure if there's a better way to avoid the circular reference error I was receiving before I converted the model to a regular Ember array. Here is the code:

        var subtypes = Ember.A();
            this.get('model').forEach(function(subtype){
            //converting the RecordArray to a regular array to 
            //avoid circular reference error
            subtypes.pushObject(subtype);
        });

        let task = this.store.createRecord('savetask', {
            id: 'savesubtypes',
            docketType: this.get('docket'),
            category: this.get('category'),
            docSubtypes: subtypes
        });
            task.save().then((result) => {
            //API returns task with modifications to
            //docSubtypes

            result.get('docSubtypes').forEach(function(subtype) {
                //need to modify the RecordArray with the changed values from 
                //the API
            }, this);

Please let me know if anything is unclear




Aucun commentaire:

Enregistrer un commentaire