Hello,
I am having some trouble with loading a specific property from an object in a table using Javascript. I have been referencing this, but to no success.
Say I have a table called “Counters” with the relations(columns): counter_name | counter_type | counter_unit
How would I be able to get the the counter_name value of both the first entry and say, the 5th entry without knowing anything such as the objectID of the entry?
So far, I have
function Counters(args) {
args = args || {};
this.counter_name = args.counter_name || "";
this.counter_type = args.counter_type || "";
this.counter_unit = args.counter_unit || "";
}
var query = new Backendless.DataQuery();
query.options = {relations:["counter_name", "counter_name.Counters" ]};
var resultCollection = Backendless.Persistence.of( Counters ).find( query, new Backendless.Async( success, gotError ) );
console.log(resultCollection);
However it is reading back as false whenever I am referencing them.
I was wondering if I could get some insight on this.
Thanks!
Hi Jerego,
you’re trying to get synchonous response from asyncshonous request by assignment the call to resultCollection
. You should define functions success
and gotError
and catch your response there.
function success(resp) {
console.log(resp); //should give you correct response
}
Regards,
Stanislav
HI Stanislav,
I actually already had my functions defined but i just didn’t put them in the original post to save room so I’m not sure that is the problem. They are defined as:
function success( user )
{
console.log( "success" );
}
function gotError( err ) // see more on error handling
{
console.log( "error message - " + err.message );
console.log( "error code - " + err.statusCode );
}
So I’m still unsure of how to go about my original problem.
Could you please export your data schema and send it to support@backendless.com?
In your success function add console.log(user)
.
Do not expect that ‘console.log(resultCollection)’ will be something else than undefined or false. You make asynchronous request, so result could be only in your success function, where you wrote only console.log(“success”) (as I see).
It should look like this:
function success( user ) {
console.log( user );
}
Let me know about your results please.
Stanislav
The last thing you mentioned got it to work!
Thanks for your help.