1
我正在構建一個使用Parse.com作爲臨時後端的原型應用程序。
這就是Parse在請求發生時如何構造返回的數據。
{
"results": [
{
"playerName": "Jang Min Chul",
"updatedAt": "2011-08-19T02:24:17.787Z",
"cheatMode": false,
"createdAt": "2011-08-19T02:24:17.787Z",
"objectId": "A22v5zRAgd",
"score": 80075
},
{
"playerName": "Sean Plott",
"updatedAt": "2011-08-21T18:02:52.248Z",
"cheatMode": false,
"createdAt": "2011-08-20T02:06:57.931Z",
"objectId": "Ed1nuqPvcm",
"score": 73453
}
]
}
我有一個工廠,看起來像這樣
app.factory('eventFactory', ['$resource', function($resource){
return $resource('https://api.parse.com/1/classes/Events', {},
{ 'get': {method:'GET'},
'save': {method:'POST'},
'query': {method:'GET', isArray:false},
'remove': {method:'DELETE'},
'delete': {method:'DELETE'}
});
}
]);
我的控制器看起來是這樣的:
app.controller('currentTradeshowsController', function($scope, eventFactory){
var testSave = eventFactory.get();
console.log(testSave);
console.log(testSave.results);
});
爲 'testSave' 第一的console.log看起來是這樣的:
where testSave.results返回undefined。
我認爲我可以通過這種方式訪問所有的對象嗎?
缺少什麼我在這裏?
任何幫助,非常感謝。
您的.get()返回一個承諾對象。要獲取實際的數據,你必須傳遞一個回調,如.get(function(response){console.log(response);});或use.then(function()... –