lundi 9 novembre 2015

Ember Promise with GitHub API

I am working with the GitHub API in my project. I need to use the API for the repos

I can not display the the list of repos i retrieve from the GitHub API although i can see the model data objects.

See the image in my console

enter image description here

Here my route code

model: function(params){
    var self, url, repoListProxy, ret;
    ret = [];
    self = this;
    url = 'http://ift.tt/1MRzF2c';
    repoListProxy = Ember.ArrayProxy.create({
        content: []
    });
    return new Ember.RSVP.Promise(function(resolve, reject) {
        return Ember.$.getJSON('http://ift.tt/1MRzF2c', function(repos) {
            if (repos.length) {
                repos.toArray().forEach(function(item, index, arr){
                    var repo;
                    repo = self.createReposList(item, repoListProxy);
                });
                repos = repoListProxy.get('content');
                return resolve(repos);
            }
        });
    });
},
createReposList: function(repo, arr){
    var record
    record = this.store.createRecord('repo',{}),
    record.setProperties({
        name: repo.name,
        description: repo.description
    })
    arr.pushObject(record);
    return record;
},

here my template

<div class="github__repos">
  {{#each repo}}
   <p>{{repo.name}}</p>
   <p>{{repo.description}}</p>
  {{/each}}
</div>

What i am doing wrong to not display the model data i retrieve from the Github Api? Am i missing something in the beforeModel method?




Aucun commentaire:

Enregistrer un commentaire