AngularJS提取JSON对象

时间:2015-10-24 12:38:02

标签: json angularjs

我通过代码从地址下载JSON数据:

  return {
        all: function () {

         // var dfd = $q.defer();
           var promise =  $http.get("http://127.0.0.1:5000/mobile/").then(function (response) {
             console.log(response.data.hits);

             return response.data;
           });
          // Return the promise to the controller


          return promise;

        }
}

控制台日志返回对象数组:

[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]

任何打开的对象都会给出:

0: Object
   $$hashKey: "object:20"
   _id: "AVCZPOdoX5ZoBStgqx-J"
   _index: "fb_events"
   _score: 1
   _source: Object
   _type: "event"
   __proto__: Object

与控制台日志级别一样,我可以访问字段_id

编辑:

他希望将数据放入一个数组中,以便通过另一个循环访问它们,这将返回一个有趣的记录。喜欢:

get: function(chatId) {
          for (var i = 0; i < chats.length; i++) {
            if (chats[i].id === parseInt(chatId)) {
              return chats[i];
            }
          }
          return null;
        }

1 个答案:

答案 0 :(得分:1)

您可以在这里发表评论......

<强> EDITED

{{1}}