为什么这个获取的数据没有显示在我的HTML中?

时间:2016-01-29 10:24:06

标签: javascript angularjs parse-platform

我从Parse数据库中获取一些对象并在我的模板中显示它们:

JS:

angular.module('yoApp')
  .controller('downloadsCtrl', function($q, $scope, $rootScope, $http, appService, serviceUpload, fileUpload) {
    $scope.downloads = []
    var Download = Parse.Object.extend('Download')
    var query = new Parse.Query(Download)
    query.find({
      success: function(results) {
        _.each(results, function(result) {
          $scope.downloads.push(result.toJSON())
          console.log($scope.downloads)
          $scope.$apply
        })
      },
      error: function(error) {
        // The object was not retrieved successfully.
        // error is a Parse.Error with an error code and message.
      }
    })
  })

HTML:

<pre>{{downloads | json}}</pre>

console.log($scope.downloads)输出对象:[Object, Object]

但他们没有在<pre></pre>

之间展示

这是为什么?以及如何实现我想要的目标?

1 个答案:

答案 0 :(得分:1)

您忘记执行$apply功能。尝试将其更改为$scope.$apply();