7

This is the Cloudboost query example:

var query = new CB.CloudQuery("Student");
query.equalTo('age', 21); //find all Students who age is 21
query.find({
success: function(list){
//list is an array of CloudObjects
},
error: function(err) {
//Error in retrieving the data.
}
});

My question is: How do i display the content of query? When i do it like this

document.write(query);

i get

[object, Object] 

If i look in the forum it should be solved with

document.write(JSON.stringify(list));

But that doesn't work. I'm in Monaca (Phonegap).

Remzo
  • 103
  • 6

2 Answers2

1

Query.find function take in an object which contains two callbacks, a success function and an error function. Success function returns a list of CloudObjects and that's what you need. Here's the sample code below :

var query = new CB.CloudQuery("Student");
query.equalTo('age', 21); //find all Students who age is 21
query.find({
success: function(list){
   console.log(list); //here's the result of the query
},
error: function(err) {
//Error in retrieving the data.
}
});
Nawaz Dhandala
  • 2,046
  • 2
  • 17
  • 23
  • 1
    While this code snippet may solve the question, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations! – Jonathan Lam Aug 08 '16 at 14:25
  • Great idea. Updated my answer – Nawaz Dhandala Aug 08 '16 at 14:50
  • Thank you for your explanation. Somehow it doesn't work on the Monaca (Phonegap) IDE. I can use: console.log('test'); in the succes function and it shows. But console.log(list); doesn't show anything. I'll try and see if a Monaca expert knows more... – Remzo Aug 08 '16 at 15:29
0

The answer is something like:

document.write(list[0].get('Student'));

so it's the getters and setters part in JS.

Thanks a lot @nawaz-cloudboost.io !!

Remzo
  • 103
  • 6