vendredi 15 janvier 2016

How to load non related models in emberjs

By design it's very difficult to load data in the component class of emberjs. But I have the following use case in which i don't see another option to do this. I have a page with blogposts, the blogposts are loaded through the router of ember. But in that page I want a sidebar with all the users that are online. Another use case is I have the same page but I want a list with the top 10 blogposts of today. I want to load the data with Ember data, I have included the store in my component but I can't get it to work.

If this needs to be done with a component can anybody show me how? Or is there another way to get this done? Below I have an example of my current code.

import Ember from 'ember';

export default Ember.Component.extend({
    store: Ember.inject.service(),
    users: null, 
    
    
    didInsertElement: function () {
        this.get('store').findAll('users').then((users) => {
            this.set('users', users)
        });
    }
});
{{#if users}}
     {{log users}}
{{/if}}



Aucun commentaire:

Enregistrer un commentaire