2015-10-05 45 views
1

我使用Parse.com作爲我的後端並遵循關於Parse文檔的基本教程。我設置了一個控制器,並且不能顯示名爲Events的數據庫表中的所有行。我將如何修復代碼以顯示錶中的所有行?ParseJS/Angular顯示解析對象行

.controller('sllc',['$scope',function($scope){ 


var Events = Parse.Object.extend("Events"); 
var query = new Parse.Query(Events); 

query.find({ 
    success: function(results) { 
    console.log(results); 
    $scope.items = results.Array; 

    }, 
    error: function(error) { 
    alert("Error: " + error.code + " " + error.message); 
    } 
}); 
}]) 

回答

0

看過一些示例代碼後,我能夠解決這個問題。我不得不應用一個額外的函數並單獨返回值。

.controller('sllc',['$scope',function($scope){ 


var Events = Parse.Object.extend("Events"); 
var query = new Parse.Query(Events); 

query.find({ 
    success: function(results) { 

    $scope.$apply(function() { 
     $scope.items = results.map(function(obj) { 

      return { 
      objectId: obj.id, 
      author: obj.get("author").id, 
      eventname: obj.get("eventname"), 
      eventDescription: obj.get("eventDescription"), 

      }; 
     }); 
    }); 

    }, 
    error: function(error) { 
    alert("Error: " + error.code + " " + error.message); 
    } 
}); 
}]) 
+0

當我這樣做,我得到'$摘要已經進行中'錯誤,任何想法爲什麼?沒有'$應用'我得到這個問題:http://stackoverflow.com/questions/34365658/parsejs-angular-ionic-retrieving-relational-object-in-view-values-getting-displ – Quisse