我是JS的新手,我不得不將它用於Cloud Code Parse功能。我有一個名爲「user_picture」的類,通過代碼我查詢所有的對象,並通過它的「城市」屬性。我希望響應是一個獨特的城市名稱數組。總之,這裏是我工作的代碼:JS代碼返回錯誤
Parse.Cloud.define("cities", function(request, response) {
var query = new Parse.Query("user_picture");
query.find({
success: function(results) {
var cities = new Array();
for (var object in results){
var tempArray = [object.get("city")];
if (cities.length > 0){
for (var i = 0; i < cities.length; i++){
if (cities[i].get("city") == object.get("city")) {
break;
} else if (i == cities.length-1) {
cities = cities.concat(tempArray);
}
}
}
}
response.success (cities);
}, error: function() {
response.error("Error");
}
});});
然而,當我運行這個功能我收到以下錯誤:
Error: TypeError: Object 0 has no method 'get'
at query.find.success (main.js:15:30)
at Parse.js:2:5786
at r (Parse.js:2:4981)
at Parse.js:2:4531
at Array.forEach (native)
at Object.E.each.E.forEach [as _arrayEach] (Parse.js:1:666)
at n.extend.resolve (Parse.js:2:4482)
at r (Parse.js:2:5117)
at Parse.js:2:4531
at Array.forEach (native) (Code: 141, Version: 1.2.18)
和響應返回null。我嘗試從結果數組中打印一個對象,以確保我收到正確的查詢,並且它打印的城市很好。可能是什麼問題呢?
結果是什麼樣的對象?它告訴你它沒有方法'get'。也許你的意思是'object.city'? – Mathletics
哪一行導致錯誤? – ppoliani
@ppoliani我無法識別代碼在Parse.com服務器上運行的錯誤。 – HusseinB