dimanche 9 décembre 2018

Ember save data to store and display without having a server api

I have a users model which fetches data from github users api (https://api.github.com/users). While displaying the list there is a add button which should add the user to a shortlist section below and which has a remove button to remove user from shortlist. I don't have api to save shortlist data. What is the best approach to make this work?

Try 1: Created a shortlist model and used store.push

this.store.push({
    data: [{
        id: user.id,
        type: 'shortlist',
        attributes: {
        login: userData.login,
        avatar_url: userData.avatar_url,
        type: userData.type
        }
    }]
});

and used item.unloadRecord(); to remove from model. But did nor found a way to fetch all record and show as this.store.peakAll('shortlist') wasen't working.

Try 2: Used localstorage to add user to shortlist, display and remove but here it needs page reload to display the add/remove changes as i used setupController to get the items from localstorage.

Please suggest how to do this in best possible way.




Aucun commentaire:

Enregistrer un commentaire