Parse.com如何获取查询的返回值 [英] Parse.com how to get return value of query
本文介绍了Parse.com如何获取查询的返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var TableObject = Parse.Object.extend(TableId);
var qyNewParse = new Parse.Query(TableObject);
qyNewParse.doesNotExist(last_sync);
qyNewParse.find({
成功:函数(结果){
},
错误:函数(错误){
}
});
var something = results.length
例如,如果我想得到result.length at功能之外。如何获取 var something 值?
解决方案
你不能有一个函数返回结果查询,因为函数将始终在查询完成之前返回。您应该为函数提供自己的回调参数,而不是让函数返回值,该参数将在查询完成时调用,如:
function some_cback(callback){
var TableObject = Parse.Object.extend(TableId);
var qyNewParse = new Parse.Query(TableObject);
qyNewParse.doesNotExist(last_sync);
qyNewParse.find({
success:function(results){
callback(results); // call callback
},
error:function(error) {
}
});
}
//调用函数
var something = some_cback(function(response){
console.log(response);
});
in Parse.Com i usually get value of query in the function. How to get it out side of the function?
var TableObject = Parse.Object.extend(TableId);
var qyNewParse = new Parse.Query(TableObject);
qyNewParse.doesNotExist("last_sync");
qyNewParse.find({
success: function(results) {
},
error: function(error){
}
});
var something = results.length
for example if i want to get result.length at outside of function. How to get var something value?
解决方案
You can't have a function return the result of a query, because the function will always return before the query is completed. Instead of having your function return a value, you should give the function its own callback parameter that will be called when the query completes, like:
function some_cback(callback) {
var TableObject = Parse.Object.extend(TableId);
var qyNewParse = new Parse.Query(TableObject);
qyNewParse.doesNotExist("last_sync");
qyNewParse.find({
success: function(results) {
callback(results); //call the callback
},
error: function(error){
}
});
}
//call the function
var something = some_cback(function(response) {
console.log(response);
});
这篇关于Parse.com如何获取查询的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文