I am trying to dynamically add items via JS code to a list depending on contents of a local storage variable. The list (named - list) is created via the UI component and has only 1 item to begin with (named listItem): I want the dynamically created list items to inherit the properties and actions of the listItem. The code is below:
var strList = localStorage.getItem('list');
var listJSON = JSON.parse(strList);
for (var i = 0, len = listJSON.length; i < len; i++) {
if (i==0)
Appery('listItem').text((listJSON));
else {
Appery('list').append( ""+listJSON+"" );
}
}
Appery('list').listview('refresh');
This works fine in terms of UI display (the multiple list items appear with appropriate text), but when I create a new onClick event for component listItem on UI to run simple JS alert("FOO"), then the dynamically created listItems above don't respond as expected (but the first item - listItem - does).
How could I fix this? Thank you for your feedback.