vendredi 4 septembre 2015

Ember.data 1.13 JSONAPI belongsTo async pass to component

I use JSONAPI as the adapter.

Model:

   App.Report = DS.Model.extend({
        'name': DS.attr('string'),
        'description': DS.attr(),
        'placemark': DS.belongsTo('placemark', {
            'async': true
        })
    });

   App.Placemark = DS.Model.extend({
        'geometry': DS.attr(),
        'description': DS.attr(),
        'reports': DS.hasMany('report', {
            'async': true
        })
    });

Route:

   App.ReportRoute = Ember.Route.extend({
        'model': function (params) {
            return this.store.find('report', params.report_id);
        },
        'renderTemplate': function () {
            this.render('report', {
                'into': 'application'
            });
        }
    });

    App.PlacemarkRoute = Ember.Route.extend({
        'model': function (params) {
            return this.store.find('placemark', params.element_id);
        },
        'renderTemplate': function () {
            this.render('placemark', {
                'into': 'application'
            });
        }
    });

i use a component for embeddeding a map canvas where the data (placemark) are come from the Report:

{{map-canvas placemark=model.placemark}}

App.MapCanvasComponent = Ember.Component.extend({
    'availablePlacemark': Ember.computed('placemark', function() {
        return this.get('placemark.geometry');
});

I found placemark is unable to retrieve and 'undefined' returned.

I tries using:

return this.get('placemark').then(function(placemark) {
    return placemark.get('geometry');

});

it did not work.

now, I am thinking if it is a JSONAPI adapter issue or async problem from view to a components.

i am using ember 1.13

Hope someone could help

thanks




Aucun commentaire:

Enregistrer un commentaire