Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need create objects for each connection.</p> <p>This objects will load the content loaded to an array. They can be represented by:</p> <pre><code>function Connection( searchQuery, callback ) { var result = []; // use to save what you load this.total; // total searching found this.getResult = function( start, length, callback ){}; // it's is one of the possibilities. // this function should verify if the content is already loaded in result[] or not. If not, load then. There is no problem of loading more then needed. } </code></pre> <p>When you conclude, it should work in the way similar to that:</p> <pre><code>var conn = new Connection( "...", objectIsWorkable ); // load the first XX results and get the total found stuff. conn.getResult( 0, 5, whenLoaded ); </code></pre> <p>After this working, then you can do what you really want:</p> <pre><code>var pageController = function( queries, callback ) { var ITEM_PER_CONNECTION = 5; var ITEM_PER_PAGE = 10; var conns = []; // used to save all connections var pages = []; // use to save the pages to be loaded var loaded = 0; var onLoadedCallback = callback; var totalConnPage; var onPageLoadedCallback; var tempPage; // the items loaded are saved here. var appendToTempPage = function( value ) { for( var i in value ) tempPage.push( value[i] ); loaded++; if( loaded == totalConnPage ) onPageLoadedCallback( tempPage ); } this.loadPage = function( num, callback ) { onPageLoadedCallback = callback; loaded = 0; tempPage = []; totalConnPage = 0; var current = pages[num]; for( var i = 0; i &lt; current.length; i++ ) { if( current[i] != null ) { conns[i].getResult( current[i][0], current[i][1], appendToTempPage ); totalConnPage++; } } } var makePages = function() { // get the total var total = 0; var totals = []; for( var i in conns ) { total += conns[i].total; totals.push( 0 ); } // create the page list while( total &gt; 0 ) { var temp = total &gt; ITEMS_PER_PAGE ? ITEMS_PER_PAGE : total; total -= temp; var page = []; var index = 0; while( temp &gt; 0 ) { if( totals[index] &lt; conns[index].total ) { if( conns[index].total - totals[index] &gt;= ITEM_PER_CONNECTION ) { var next = temp &gt; ITEM_PER_CONNECTION ? ITEM_PER_CONNECTION : temp; page.push( [totals[index], next] ); totals[index] += next; temp -= next; } else { var next = conns[index].total - totals[index]; next = next &gt; temp ? temp : next; page.push( [totals[index], next] ); totals[index] += next; temp -= next; } } else page.push( null ); index++; } pages.push( page ); } } var inited = function() { pages[loaded] = 0; loaded++; if( loaded == conns.length ) { makePages(); onLoadedCallback(); } } // init for( var i in queries ) conns.push( new Connection( queries[i], inited ) ); } </code></pre> <p>The most import thing is the <code>makePages</code>, probably is what you are wonderring to do. But your question is a little long then I put a little more stuff to not be confusing.</p> <p>You can change <code>makePage</code> to work in your way. The idea is saving all pages contents in <code>pages</code> var.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload