lundi 9 janvier 2017

Ember findRecord and include

I have a component which needs to query a service for homes in a postcode. This is to populate a select dropdown list in response to a user entering a postcode.

So I have

export default Ember.Component.extend({
    store: Ember.inject.service(),
    actions: {
        findHome: function(){
            //todo:Make a call to API to fetch the address
            var component = this;
            var postcode = this.get( 'area.postcode');
            var store = this.get('store');

            // EITHER...
            var x = store.findRecord('postcode', postcode, {include: 'homes'}).then( function (area) {
                component.set( 'homes', area.homes);
            });

            // OR...  
            var x = store.findRecord('postcode', postcode, {include: 'homes'})
            component.set( 'homes', x.homes );

        }
    }
});

Anyway,it doesn't work as neither solution has a proper array of homes. How should I be doing this?

I can see Mirage returning the data (postcode and included homes) in response to the findRecord.




Aucun commentaire:

Enregistrer un commentaire