jeudi 27 juillet 2017

get data from store return undefined in ember

I have some problem with get data from storage.

Isset model orders:

import DS from 'ember-data';

export default DS.Model.extend({
   test: DS.hasMany('dealer-status'),
});

adapter (its is test data). I havn't normolize responce and i add params to data for normalize. It is implementation will be in serialize :

export default DS.JSONAPIAdapter.extend({
service:  Ember.inject.service('admin.auth'),
query(store, type, query) {

    var service = this.get('service');
    return new Ember.RSVP.Promise(function (resolve, reject) {

        service.fetch(query).subscribe(
            res => {

                var data = {
                    "data": [{
                        "type": "user",
                        "id": "1",
                        "attributes": {
                            test: 'test'

                        }
                    }]
                };
                resolve(data);
            },
            err => {
                reject(err);
            });
    });
}
});

The router:

model() {

    return   this.get('store').query('orders', {}).then(res => {
        console.log(res.get('test')); //undefined
        console.log(res.objectsAt(0)); //undefined

    })

In router I find by query, but i can't get param test. In Promise res.get('test') return undefined.

Why i get undefined in promise? How fix it?




Aucun commentaire:

Enregistrer un commentaire