Page 1 of 1

localstorage JSON array not displaying following upgrade

Posted: Fri Oct 03, 2014 9:06 am
by Chris6743166

I have a couple of pages which are supposed to display data from a locally stored stringified JSON array. However, these pages no longer display the data and instead remain blank.

To recreate the problem, click News, then Search and either select a category from the drop down or enter 'rec' (for example) into the input and hit search.

I've had a good look but cannot work out what the issue is.

This is the app:
http://appery.io/app/view/25807b5d-c4...

It is share with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a.

Your help is appreciated. Thanks.


localstorage JSON array not displaying following upgrade

Posted: Fri Oct 03, 2014 10:24 am
by Kateryna Grynko

Hi Chris,

Is your data saved to localStorage?
In what variable the data is supposed to be stored?

You can also check how to work with localStorage after upgrade:
http://devcenter.appery.io/documentat...


localstorage JSON array not displaying following upgrade

Posted: Fri Oct 03, 2014 10:54 am
by Chris6743166

The data is stored in localstorage as the variable 'json_news'.

This is the javascript I'm using to filter the data:

pre
Appery.get_cache_news_filtered_js = Appery.createClass(null, {

Code: Select all

 init: function (requestOptions) { 
     this.__requestOptions = $.extend({}, requestOptions); 
 }, 

 process: function (settings) { 
     settings.beforeSend(settings); 
     if (this.__requestOptions.echo) { 
         settings.success(this.__requestOptions.echo); 
     } else { 

         var cdata = JSON.parse(Apperyio.storage.json_news.get()); 
         var category_slug = Apperyio.storage.category_slug.get(); 
         //alert(category_slug); 

         var filter_data = []; 
         jQuery.grep(cdata.posts, function (post, key) { 
             var found = false; 
             post.categories.forEach(function (category) { 
                 if (category.slug == category_slug) { 
                     found = true; 
                 } 
             }); 
             if (found) { 
                 filter_data.push(post); 
             } 
         }); 
         cdata.posts = filter_data; 

         var cdata_filtered = JSON.stringify(cdata); 
         //Apperyio.storage.json_news_filtered.set(cdata_filtered); 
         //alert(cdata_filtered); 

         settings.success(cdata_filtered); 
         settings.complete('success'); 

     } 
     settings.complete('success'); 
 } 

});
/pre

This is the javascript I'm using to search the data:

pre
Appery.get_cache_news_searched_js = Appery.createClass(null, {

Code: Select all

 init: function (requestOptions) { 
     this.__requestOptions = $.extend({}, requestOptions); 
 }, 

 process: function (settings) { 
     settings.beforeSend(settings); 
     if (this.__requestOptions.echo) { 
         settings.success(this.__requestOptions.echo); 
     } else { 

         var cdata = JSON.parse(Apperyio.storage.json_news.get()); 
         var search_term = Apperyio.storage.search_term.get(); 
         localStorage.removeItem("search_found"); 

         var search_data = []; 
         jQuery.grep(cdata.posts, function (post, key) { 
             var found = false; 
             if (post.content.toLowerCase().indexOf(search_term.toLowerCase())  0) { 
                 search_data.push(post); 
                 found = true; 
                 Apperyio.storage.search_found.set(found); 
             } 
         }); 
         cdata.posts = search_data; 

         var cdata_searched = JSON.stringify(cdata); 
         //Apperyio.storage.json_news_searched.set(cdata_searched); 

         settings.success(cdata_searched); 
         settings.complete('success'); 

     } 
     settings.complete('success'); 
 } 

});
/pre

Since the upgrade I have changed all localstorage calls to use your storage API, but this did not fix the problem.


localstorage JSON array not displaying following upgrade

Posted: Fri Oct 03, 2014 12:40 pm
by Kateryna Grynko

Hi Chris,

Please replace:presettings.success(cdata_searched);/preWith:presettings.success(cdata);/pre


localstorage JSON array not displaying following upgrade

Posted: Fri Oct 03, 2014 12:50 pm
by Chris6743166

Fixed. Thank you Kateryna!