mardi 24 janvier 2017

How do I set up ember-cli to get at the values in a JSON file

How do I set up ember-cli to get at the values with the keys "remaining", "success" and "deck_id" from the following JSON file?

I can see in my console>Network>HXR that I am receiving JSON data that looks like this:

{
   "remaining": 49,
   "success": true,
   "deck_id": "79n773qlsciez",
   "cards": [
      {
         "suit": "HEARTS",
         "image": "http://ift.tt/2kcJL1Q",
         "images": {
            "svg": "http://ift.tt/2j09LAz",
            "png": "http://ift.tt/2kcJL1Q"
         },
         "code": "JH",
         "value": "JACK"
      }
   ]
}

Here is the rest of my setup:

//adapters/card.js
import DS from 'ember-data';

export default DS.RESTAdapter.extend({
    host: "http://ift.tt/2kcC8sa",
    namespace: "api/deck/79n773qlsciez/draw/",

    pathForType(){
        return "?count=1";
    }
});

and

//app/models/card.js

import DS from 'ember-data';

export default DS.Model.extend({

image: DS.attr("string"),
code: DS.attr("string")
});

and

//app/serializers/card.js
import DS from 'ember-data';

export default DS.RESTSerializer.extend({
     primaryKey: 'code',

});

and

//app/routes/cards.js

import Ember from 'ember';

export default Ember.Route.extend({
    model() {
    return this.store.findAll("card");
    }
});

and last but not least

//templates/cards.hbs
<h2>All cards here</h2>



<img src="" alt="">






Aucun commentaire:

Enregistrer un commentaire