ArnisR Posted June 25, 2011 Report Share Posted June 25, 2011 Kā JavaScript cookie'jā saglabāt multidimensionālo masīvu? // Izmantoju šo cookie plug-in: http://www.electrictoolbox.com/jquery-cookies/ Quote Link to comment Share on other sites More sharing options...
Rincewind Posted June 25, 2011 Report Share Posted June 25, 2011 Kā JavaScript cookie'jā saglabāt multidimensionālo masīvu? // Izmantoju šo cookie plug-in: http://www.electrictoolbox.com/jquery-cookies/ JS masīviem - JSON PHP masīviem - serialize/unserialize Manuprāt tā. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted June 25, 2011 Report Share Posted June 25, 2011 Šādi neiet? var myArray = { 'a': { a1: 'foo', a2: 'bar' }, 'b': { b1: 'foo', b2: 'bar', b3: 'baz' } }; $.cookie( 'myCookie', myArray ); Quote Link to comment Share on other sites More sharing options...
ArnisR Posted June 25, 2011 Author Report Share Posted June 25, 2011 Šādi neiet? var myArray = { 'a': { a1: 'foo', a2: 'bar' }, 'b': { b1: 'foo', b2: 'bar', b3: 'baz' } }; $.cookie( 'myCookie', myArray ); Tieši tā arī mēģināju, bet nekā! Kad to cookie masīvu ieliec funkcijā, - manaFunkcija($.cookie('myCookie')); - tad nekas nestrādā, savukārt, ja ieliec myArray, tad viss aiziet! Quote Link to comment Share on other sites More sharing options...
daGrevis Posted June 25, 2011 Report Share Posted June 25, 2011 Bet kā cepums var saturēt masīvu? Nokodē to kā stringu (izmantojot jau minēto JSON) un tad saglabā cepumā... Quote Link to comment Share on other sites More sharing options...
codez Posted June 25, 2011 Report Share Posted June 25, 2011 (edited) Ja vajag stringu, tad no sākuma vajag pārkonvertēt to masīvu par stringu un tāpat vajag arī pankonvertēt pēc tam atpakaļ par masīvu, kad nolasa to stringu. Piemēram, ar šo pluginu: http://code.google.com/p/jquery-json/ Edited June 25, 2011 by codez Quote Link to comment Share on other sites More sharing options...
ArnisR Posted June 26, 2011 Author Report Share Posted June 26, 2011 Bet kā par masīvu pārveidot šādu string'u, bez jeb kādu plug-in'u palīdzības: 1,aaa,bbb|2,ccc,ddd|3,eee,fff Rezultātā jāiegūst: var arr = [[1,aaa,bbb], [2,ccc,ddd], [3,eee,fff]] Quote Link to comment Share on other sites More sharing options...
codez Posted June 26, 2011 Report Share Posted June 26, 2011 http://jsfiddle.net/2c5yz/1/ s='1,aaa,bbb|2,ccc,ddd|3,eee,fff'; d=s.split('|'); m=[]; for(var i in d){ m.push(d[i].split(',')); } console.info(m); Quote Link to comment Share on other sites More sharing options...
ArnisR Posted June 26, 2011 Author Report Share Posted June 26, 2011 http://jsfiddle.net/2c5yz/1/ s='1,aaa,bbb|2,ccc,ddd|3,eee,fff'; d=s.split('|'); m=[]; for(var i in d){ m.push(d[i].split(',')); } console.info(m); Liels paldies! Tieši tas, kas vajadzīgs! ;) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.