Chris6743166
Posts: 1
Joined: Tue Mar 18, 2014 11:50 am

Populate existing grid from localstorage array.

Mapping an array to a grid is very easy using Appery's edit mapping interface, however, I'm now trying to retrieve an array from local storage and populate the same grid but I'm having difficulty.

I am saving JSON to local storage on success like this:

var response = JSON.stringify(data);
localStorage.setItem("json_response", response);

...and then retrieving the data on page load like this:

var storedData = localStorage.getItem('json_response');
if (storedData) {
ArrayData = JSON.parse(storedData);
}

However, I'm a little lost with how to map the array to my existing grid . The grid is a simple 1 column, 3 row table. Each row contains a label and each label should be populated with a value from the array. The table should then be repeated.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Populate existing grid from localstorage array.

Hello Chris,

If you want to use appery.io UI mapping you should use generic service: http://docs.appery.io/documentation/u...

Chris6743166
Posts: 1
Joined: Tue Mar 18, 2014 11:50 am

Populate existing grid from localstorage array.

Hi Evgene,

Thanks for the quick reply. I haven't worked it out yet, but I get the idea.

I have created a generic service (get_cache_news) with the following custom implementation:

code
Appery.get_cache_news_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 {  
         // load JSON data from local storage 
         var cdata = localStorage.getItem("json_response"); 

         // pass the JSON to the service, for output mapping 
         settings.success(JSON.parse(cdata));          
     } 
     settings.complete('success'); 
 } 

});
/code

I then automatically created parameters using a sample response (copied from the original REST service test - assuming the REST and localstorage responses are the same). I then mapped the response values to their destination components.

This is the javascript script I am currently running on load:

code
if (navigator && navigator.network && navigator.network.connection && navigator.network.connection.type) {
//alert('navigator');
var networkState = navigator.network.connection.type;

Code: Select all

 if (networkState !== Connection.NONE) { 
     //alert('online'); 
     onOnline(); 

 } else { 
     //alert('offline'); 
     onOffline(); 

 } 
 // When debug only (in desktop browser) 

} else {
//alert('not navigator');
onOnline();
}

// On offline
function onOffline() {
get_cache_news_data.execute(); //this is my generic service
}

// On online
function onOnline() {
get_news_data.execute(); //this is my REST service
get_category_data.execute();
}
/code

However, this does not work. With this implementation, I am now unable to progress to the news page, or any other page in the app. Am I missing something?

Chris6743166
Posts: 1
Joined: Tue Mar 18, 2014 11:50 am

Populate existing grid from localstorage array.

The act of creating a generic service with a custom implementation causes the app to hang when navigating to any page.

I'm getting this error in Chrome:

Uncaught TypeError: undefined is not a function (service.js:29)

This is line 29 of service.js:

codeget_cache_news = new Apperyio.get_cache_news_js({});/code

What is more, I'm not seeing my custom implementation javascript file (get_cache_news_js.js) listed as a source in Chrome.

I'd appreciate some help with this.

Chris6743166
Posts: 1
Joined: Tue Mar 18, 2014 11:50 am

Populate existing grid from localstorage array.

Hi Evgene,

This topic has been marked as answered, however, the problem has not been solved. There is an ongoing problem with the app, as stated in my previous post.

I have shared the app with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a if this enables you to more easily solve the problem. The project id is 25807b5d-c468-4bd9-8335-c2d667d1796c.

Thank you.

Chris

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Populate existing grid from localstorage array.

Hi Chris,

Don't worry, this means it has at least one answer from us.
Thank you for sharing! We'll test it.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Populate existing grid from localstorage array.

Hi Chris.

We have investigated your APP and found that you have modified "home" page in source.

Please see this screen shot: http://prntscr.com/3h7hqz/direct

It’s important to remember that if you try to make any changes in the visual builder after you have edited the source, the changes won’t be seen.

To get builder work for your "home" page please restore your files.

How to do it here: http://docs.appery.io/tutorials/sourc...

So just delete this files and make "Undo all changes" for the folder.

Regards.

Chris6743166
Posts: 1
Joined: Tue Mar 18, 2014 11:50 am

Populate existing grid from localstorage array.

Much appreciated. This totally solved the problem.

Return to “Issues”