locked
Count items in a query in Javascript RRS feed

  • Question

  • I want to count, in Javascript, the number of items that my query has. I want to do this in the created method.

    These return me 0 :

    • screen.[MyQuery].data.length;
    • screen.[MyQuery].count;

    Does anyone have an idea?

    Thursday, July 4, 2013 9:16 AM

Answers

  • screen.MyQuery.data is loaded asynchronously when a screen is created and thus will not be immediately available to provide you an accurate count before the _created method completes. 

    Using a promise object to retrieve this information may work instead:

    screen.getQueryScreen().then ( function (results) { var queryCount = results.count;
    // etc ...
    });

    • Marked as answer by Rom's Friday, July 5, 2013 7:50 AM
    Friday, July 5, 2013 12:38 AM

All replies

  • screen.MyQuery.data is loaded asynchronously when a screen is created and thus will not be immediately available to provide you an accurate count before the _created method completes. 

    Using a promise object to retrieve this information may work instead:

    screen.getQueryScreen().then ( function (results) { var queryCount = results.count;
    // etc ...
    });

    • Marked as answer by Rom's Friday, July 5, 2013 7:50 AM
    Friday, July 5, 2013 12:38 AM
  • Thank you AllenAdams. That's exactly what I wanted.

    Solved.

    Friday, July 5, 2013 7:51 AM