neogucky
Posts: 0
Joined: Fri Feb 14, 2014 1:32 pm

Programmaticly populate List and use click event

I have an app which gets some data via REST. With this data I fill a List-Component via the hidden-ID concept introduced here (http://docs.appery.io/tutorials/build...) This works perfectly.

Now I change my App to get offline compatibility. All REST-Data will be downloaded and stored in the localStorage. The List-Component is populated like this:

----------------------------

var list = Appery("AllQuestions");
var item = Appery("AllQuestionsItem");

for (x in activeMission.Question){
var itemToAppend = item.clone();
itemToAppend
.attr('style', '')
.attr('id', 'QuestionsList_AllQuestionsItem'+x)
.attr('idx', ''+x);
itemToAppend.children().children('#QuestionsList_QuestionName')
.text(activeMission.Question[x].name)
.attr('id', '#QuestionsList_QuestionName'+x)
.attr('idx', ''+x);
itemToAppend.children().children('#QuestionsList_QuestionID')
.text(activeMission.Question[x].id)
.attr('id', '#QuestionsList_QuestionID'+x)
.attr('idx', ''+x)
itemToAppend.appendTo(list);
}
item.remove(); // remove the proto-listitem
list.refresh();

----------------------------

When I now use the appery.io click method to set the localStorage-ID like before, it selects always the first entries id. Is there something missing or even a better way to populate the List with js?

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Programmaticly populate List and use click event

Hello,

You could use code for offline mode from "Building a ToDo app, pt. 2: offline mode" tutorial.

neogucky
Posts: 0
Joined: Fri Feb 14, 2014 1:32 pm

Programmaticly populate List and use click event

Thank you,

I saw that tutorial before but didn't realized that it held my answer. For other people having the same problem:

You can emulate a service with local data. Just create a RESTService and map its response values. After that you can just "forge" a REST-call and define any json answer you want:

NAME_OF_YOUR_SERVICE.service.__requestOptions.echo = '{ data : 'this json code has to be a string'}';
NAME_OF_YOUR_SERVICE.execute();

Return to “Issues”