I am performing a query on users(titanium cloud service) as such:
Cloud.Users.query({
page: 1,
per_page: 5,
where: {
email: '[email protected]'
}
}, function(e) {
if (e.success) {
alert(JSON.parse(e.users));
} else if (e.error) {
alert(e.message);
} else {}
});
After executing the query I am unable to parse e.users
on success
, alert
returns nothing. Any thoughts?
You're trying to parse e.users which is an array. You should traverse through the array using a loop and you can simply alert each user using JSON.stringify
method
Try the following code
Cloud.Users.query({
page: 1,
per_page: 5,
where: {
email: '[email protected]'
}
}, function (e) {
if (e.success) {
alert('Total Users: ' + e.users.length);
for (var i = 0; i < e.users.length; i++) {
var user = e.users[i];
alert(JSON.stringify(user)); //This line will display the details of the user as a string
}
} else {
alert('Error:\n' +
((e.error && e.message) || JSON.stringify(e)));
}
});
You should read Titanium.Cloud.Users module. Documentation itself shows how to query users.