javascript - Create array of Pages -


this may seem basic request. head fuzzy figure out correct way of doing this.

i have multi-dimensional array of keywords. these being split columns. plan on limiting them 2 appearing in column @ time. 5 columns total, each consisting of 2 keywords. consists of "page".

what have below wrong. inner for i'm attempting assign page, incorrect. outer for exactly need (limits data 2 words/column).

for (i; < keyworddata.length; i++) {     nkeyworddata[i] = keyworddata[i].splice(start,limit);     (var k=0; k < nkeyworddata.length; k++){         pages[k] = nkeyworddata;     } } 

sample data:

$rootscope.keyworddata = [     ["column1","test1","test1","tea","party", "water bottle"],     ["column2","test2","test2","test2 test2"],     ["column3","test3","t3","longer test3 "],     ["column4","test4","testing4 tesf asdfsdf"],     ["column8","test5","test5 asdfsdfasdfasdfasa asda asdfsas"] ]; 

i have other functions in place handle putting things columns, etc. can't pages work.

expected outcome: 3 pages, last page have party, water bottle in array, longest. other arrays empty.

this first "page" like. click "show more" next "page" appended below it.

keygenshowmore

this give array pages described. let me know if missed something.

var idxpage; (var i=0; < keyworddata.length; i++) {     column = keyworddata[i];     for(var k=0; k < column.length; k++){         idxpage = math.floor(k / limit);         if (!pages[idxpage]){             pages[idxpage] = [];            }         if (!pages[idxpage][i]){             pages[idxpage][i] = [];            }         pages[idxpage][i].push(column[k]);      } }  alert(pages[0][0]);   // ["column1", "test1"] alert(pages[0][1]);   // ["column2", "test2"] alert(pages[1][0]);   // ["test1", "tea"] alert(pages[1][1]);   // ["test2", "test2 test2"]  alert(pages[2][0]);   // ["party", "water bottle"] alert(pages[2][1]);   // undefined 

here fiddle


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -