mercredi 9 décembre 2015

Requests to different backend endpoint from same route and save the result in different model

I have a designed a app in ember.Now the app has feed page similar to fb and instagram.Now to get the username and his display pic, I have to send the request to "http://ift.tt/1NS6RkP" and the to get the user feed I have to make the requests to "http://ift.tt/1OlP1vf".I am not able to figure out how to do it.

routes.js

import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';

export default Ember.Route.extend(AuthenticatedRouteMixin,{
    model(){
       return Ember.$.ajax({
        url: 'http://ift.tt/1Ni0uHM',
        headers:{
         "Authorization":"token b0fb466a6eac3ad87cd200058042fb2192b85ab4"
        },
        success:function(user_details)
        {
        console.log(user_details.full_name);
        }
  });

},
model(){
    var inflector = Ember.Inflector.inflector;
    inflector.uncountable('feed');
    return this.store.findRecord('feed');
}
});

But in this case request is made only to "http://ift.tt/1OlP1vf" and the ajax call is left.

I also want to store the data from both call to different store ,So that I can use it in hbs.

my models feed.js

import DS from 'ember-data';

    export default DS.Model.extend({
         FeedResult: DS.attr(),
           // gallery_name:DS.attr(),
           // feedPhotos:DS.attr()
    });

profile.js

import DS from 'ember-data';

export default DS.Model.extend({
  results: DS.attr(),
  photos:DS.attr()
});

Please suggest how should I do this so I can display the username,display pic and his feed on same page just like fb and instagram.




Aucun commentaire:

Enregistrer un commentaire