我的Parse Javascript云代码无法正常工作。基本上我的所有对象都有相应的“index / menindex& womenindex”数字。
如果选择了两种性别 - 所有项目都会显示(应该如此)。
如果只选择男性或女性 - 它只显示最高122309(女性指数)或80811(男性指数)的项目。我已经试了几个星期,但无法想出这个。
Parse.Cloud.define("standardQuery", function(request, response) {
var maxIndex = 124940;
var maxWomenIndex = 135354;
var maxMenIndex = 105357;
var arrayOfRandomNumbers = new Array();
var query = new Parse.Query("garmentsAPI");
if (request.params.gender === "Female") {
//arrayOfRandoms draws on womenIndex, gender set to female
for (var k = 0; k < 40; k++) {
var randomIndex = Math.floor((Math.random()*maxWomenIndex)+1);
arrayOfRandomNumbers.push(randomIndex);
}
query.containedIn("womenIndex", arrayOfRandomNumbers);
query.notEqualTo ("viewers", request.params.user);
}else if (request.params.gender === "Male") {
for (var k = 0; k < 35; k++) {
var randomIndex = Math.floor((Math.random()*maxMenIndex)+1);
arrayOfRandomNumbers.push(randomIndex);
}
query.containedIn("menIndex", arrayOfRandomNumbers);
query.notEqualTo ("viewers", request.params.user);
//arrayOfRandoms draws on menIndex, gender set to male
}else{
for (var k = 0; k < 35; k++) {
var randomIndex = Math.floor((Math.random()*maxIndex)+1);
arrayOfRandomNumbers.push(randomIndex);
}
query.containedIn("index", arrayOfRandomNumbers);
query.notEqualTo ("viewers", request.params.user);
};
if (request.params.gender !== "both") {
query.equalTo ("gender", request.params.gender);
};
query.find({
success: function(objectsInQuery){
if (objectsInQuery.length > 15) {
var arrayOSelectedObjects = new Array();
for (var j = 0; j < 15; j++) {
arrayOSelectedObjects.push(objectsInQuery[j]);
}
response.success(arrayOSelectedObjects);
} else{
// var existingCount = objectsInQuery.count;
var missingIndex = 15 - objectsInQuery.length;
// missingIndex = missingIndex - objectsInQuery.count;
var query = new Parse.Query("garmentsAPI");
if (request.params.gender !== "both") {
query.equalTo ("gender", request.params.gender);
};
query.notEqualTo ("viewers", request.params.user);
query.limit(missingIndex);
// query.limit = 9 - objectsInQuery.count;
query.find({
success: function(objectsInQuery2){
if ((objectsInQuery.length + objectsInQuery2.length) === 15) {
for (var l = 0; l < missingIndex; l++) {
objectsInQuery.push(objectsInQuery2[l]);
}
response.success(objectsInQuery);
} else {
//who knows
var maxIndex2 = 15000;
var arrayOfRandomNumbers2 = new Array();
for (var m = 0; m < 15; m++) {
var randomIndex = Math.floor((Math.random()*maxIndex)+1);
// var randomIndex = 15;
arrayOfRandomNumbers2.push(randomIndex);
}
var query = new Parse.Query("garmentsAPI");
query.containedIn("index", arrayOfRandomNumbers2);
if (request.params.gender !== "both") {
query.equalTo ("gender", request.params.gender);
};
// query.notEqualTo ("viewers", request.params.user);
query.limit(15);
query.find ({
success: function (objectsInQuery3){
response.success (objectsInQuery3);
},
error:function() {
response.error("there was an error");
}
});
};
},
error:function() {
response.error ("didn't work");
}
}
);
};
},
error:function() {
response.error ("didn't work");
}
});
});
答案 0 :(得分:0)
对于初学者来说,你发布的所有大括号都不匹配。具体来说,我无法找到此if
声明的右括号......
if (objectsInQuery.length > 15) {
根据您发布的内容,它应该是第173行的第一个字符......
就这样......
});
};
},
error:function() {
response.error ("didn't work");
}
});
});
VS。你的帖子,如下......
);
};
},
error:function() {
response.error ("didn't work");
}
});
});