How can one count the number of results from a JSON request before it is rendered into a list or grid?
Also, how can one append to a list or grid rather than overwriting it with new data?
var count = data.results.length;
'results' is the actual array name, the variable in your JSON object might be different.
As for appending, it has to be implemented by the developer. One option is to save all data into local storage, combine, and then run a Generic Service to do the mapping: https://getsatisfaction.com/tiggzi/to...
Max-I am trying to count my collection results as you describe:
I run this on service success:
//the following line does not get count and creates exception of data is not defined / cannot read property length of undefined.
//var count = data.results.length;
//this logs count correctly but creates exception that data is not defined.
var count = data.length;
I am confused about how I could be getting the correct count and the error at the same time. How to I access the length correctly?
The variable "data" points to data got from Rest Service.
In Max's example array was stored in response parameter "result". If Rest service returns an array then your code for array length definition is correct:
codevar count = data.length;/code
The error "data is not defined" may be caused by JS code in another Action. Do you have an Action on "Complete" event?
the array makes sense. With regard to the error on data, I did have a complete action but deleted it. I now only have one action under Data on success.
When I watch the console, the exception occurs after the successful count is logged. I thought that I might have lest a test bit of code somewhere else but cannot find it. both the count result and the error occur in the same js file
Uncaught ReferenceError: data is not defined startScreen.js:299
thanks- the problem appeared to be with execution order. I invoked service on button click, then page transitioned, but on data side I ran script to get count on service success. By moving page transition to data side after script ran, error went away. thanks.
hello! I am looking for a similar line of code on Success.
my count query works when tab-test the service.
however, may I ask you for the proper line of code to forward that count result to a localStorage or a Appery label ?
thk you in advance,