我在这段不想工作的代码上花了8个小时
在localhost和javascript上工作得很好,但是在parse.com云代码中我得到一个变量未定义。
Parse.Cloud.define("goGetPrices", function(request, response) {
var price;
function getPrices(stockPrice){
console.log(stockPrice);
var PriceTick = Parse.Object.extend("StockPrices");
var queryInstal = new Parse.Query(Parse.Installation);
var queryLess = new Parse.Query(PriceTick);
var queryMore = new Parse.Query(PriceTick);
queryLess.equalTo("Position","Less");
queryLess.greaterThan("Price", stockPrice);
console.log(PriceTick) // RETURNS UNDEFINED
console.log(queryInstal) // RETURNS UNDEFINED
因为那些返回未定义的其余代码无法工作...奇怪的是,这在我的localhost上没有云代码很好用
queryLess.find({
success: function(results) {
//Less than
console.log("found less");
if (results.length) {
for (var i = 0; i < results.length; i++) {
var object = results[i]
var devicetoken = object.get('devicetoken');
var objID = object.get('objectId');
console.log("Got Less");
queryInstal.equalTo('deviceToken', devicetoken);
queryInstal.equalTo('deviceType', 'ios');
Parse.Push.send({
where: queryInstal, // Set our Installation query
data: {
alert: "The price is now: "+stockPrice
}
}, {
success: function() {
// Push was successful
object.destroy({});
},
error: function(error) {
// Handle error
}
});
}
}},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
Parse.Cloud.httpRequest({
url: "example.php",
dataType: 'json',
type: 'GET',
success: function(data) {
price = data.data.Response.price;
response.success("yes")
getPrices(price);
},
error: function(data) {
response.error('Request failed with response code ' + data.status);
}
}); });
答案 0 :(得分:2)
你必须使用Parse.Query(ClassName)
,
其中ClassName
是Parse.Object
子类的名称字符串或实例: