JSON 数据使用 ember.js

JSON Data using ember.js

以下是 API 回复(示例 url http://api.example.com/data.json

{
      "results":[
        {
          "id":"4422",
            "updated":"Mon Jun 26 15:01:05 GMT 2006",
              "description":"Meet fellow Social Networkers near you! Come to a local Social Networking Meetup to make valuable social connections and cultivate relationships with other elbow-rubbers in your area.",
             "name":"Social Networking",
             "link":"http:\/\/socialnetwork.meetup.com\/",
             "urlkey":"socialnetwork",
             "members":"245701"
          }
       ],
       "meta":{
          "id":"",
          "title":"Meetup Topics",
          "count":1,
          "updated":"",
          "description":"API for accessing meetup topics",
          "next":"",
          "link":"http:\/\/api.meetup.com\/topics\/",
          "method":"Topics",
          "total_count":3063,
          "url":"http:\/\/api.meetup.com\/topics\/\/?order=members&key=1&page=1&format=json&desc=0&offset=0",
          "prev":""
       }
    }

使用纯 javascript,我可以做到

var req = new XMLHttpRequest();
req.open('GET', 'http://api.example.com/data.json', false);
req.send();
json = req.responseText;
object = JSON.parse(json)['results'];
console.log(object.id);
console.log(object.link);

我如何使用 ember.js 和 ember-data 获得它,能够访问属性?

您可能无法在这种情况下使用ember-data,因为如果您想要,要么需要遵循conventions the or create your own adapter

但是您仍然可以在没有 ember 数据的情况下使用这些数据,使用普通的旧 jQuery。

var request = Ember.$.getJSON('http://api.example.com/data.json');

request.then(function(object) {
 console.log(object);
});