Suppose I've this array object var tempRows = new Array(); tempRows.push({name:"vj",rollNo:10}); tempRows.push({name:"kr",rollNo:20});
I tried to do this copied all of your functions and $cookieName = 'rowCookie'; $sitedata = tempRows; /* where tempRows is array of objects */ getSetCookies(false); tempRows = getSetCookies(true); alert(tempRows.length) // which should return 2 When I tried to do this I got following error. $.iLogger has no properties in funtion getSetCookies. Do I need to have some plugin to remove this error. Potluri wrote: > > Hi can you please tell me the syntax of calling these functions. I tried > to do the following. > > var $cookieName = "arrCookie" //Assuming this is the cookie name > > where the value of the cookie is been set like in my case value should be > array of objects?????. > > 1>> how to set value of this cookie ? > I copied all the functions given by you > sterilizeQueryString = function(input,splitter,pair){ > try{ > if(typeof input != 'string') return null; > if(!splitter){ > splitter = "&"; > } > if(!pair) pair ="="; > var a = input.split(splitter), b = Array(); > for(var i=0; i < a.length; i++) a[i] = a[i].split(pair); > > for(var i = 0; i < a.length; i++) b[a[i][0]] = a[i][1]; > > return b; > } > catch(e){ > $.iLogger.log(e.name + ': ' + e.message, > 'error','sterilizeQueryString();'); > }; > }; > > objectToQueryString = function( a , joiner, pair) { > try{ > var s = []; > if(!pair) pair ="="; > if((typeof a == "object")){ > for(var j in a){ > if(typeof a[j] == "object" && a[j]){ > s.push(encodeURIComponent(j) + pair + "__" > +objectToQueryString(a[j],"**","##") +"__"); > } > else{ > s.push( encodeURIComponent(j) + pair > +encodeURIComponent( a[j] ) ); > } > }; > return s.join(joiner); > } > else{ > return a; > }; > } > catch(e){ > $.iLogger.log(e.name + ': ' + e.message, > 'error','objectToQueryString();'); > }; > }; > > queryStringToObject = function(s){ > try{ > if(s && typeof s == "string"){ > s = sterilizeQueryString(s); > for(var j in s){ > if(/__(.*)__/.test(s[j])){ > s[j] = s[j].replace(/__/g,""); > s[j] = sterilizeQueryString(s[j],"**","##") > }; > }; > return s; > } > else{ > return s; > }; > } > catch(e){ > $.iLogger.log(e.name + ': ' + e.message, > 'error','queryStringToObject();'); > }; > } > /** >> > * @name getSetCookies >> > * @example getSetCookies(); >> > * @param {Boolean} getOnly >> > * @desc Purpose of this function is to set and get cookie data >> > * @see objectToQueryString >> > * @see queryStringToObject >> > */ >> > getSetCookies = function(getOnly){ >> > $.iLogger.log('getSetCookies();'); >> > try{ >> > // >> > if(getOnly){ >> > var tempSiteData = $.cookie($cookieName); >> > if(tempSiteData){ >> > $sitedata = queryStringToObject(tempSiteData); >> > } >> > else{ >> > $.cookie($cookieName, >> objectToQueryString($sitedata,"&"), >> > $cookieParams); >> > } >> > } >> > else{ >> > $.cookie($cookieName, objectToQueryString($sitedata,"&"), >> > $cookieParams); >> > }; >> > } >> > catch(e){ >> > $.iLogger.log(e.name + ': ' + e.message, 'error', >> > 'getSetCookies();'); >> > }; >> > }; // end : getSetCookies > > I've doubt like do I need to use only getSetCookies function to get and > set the object of array from cookie. or > > As of my assumption getSetCookies(false) should be used to set the value > of cookie to query string. > and getSetCookies(true) should bring back the array of object. > > I think I'm missing something like how to set the value of cookie to be > object of array and whats the exact syntax of how to make this work after > copying the functions you've given. > I hope you'll clarify my doubt. > > Thanks. > > > -- View this message in context: http://www.nabble.com/problem-with-cookie-plugin-when-trying-to-store-array-object-in-cookie-tf4516799s15494.html#a12889212 Sent from the JQuery mailing list archive at Nabble.com.