I am trying to develope an application, and I'm using jQuery mobile for the UI. Does anybody know how to add a listview in a collapsible (as category) dynamically using JavaScript?
HTML:
<div data-role="content" id="introContent">
<p id="introContentNoFeeds" style="display:none">welcome!
</p>
<ul id="feedList" data-role="listview" data-inset="true" data-split-icon="delete">
</ul>
<a href="addfeed.html" data-role="button" data-theme="b">Add Feed</a>
</div>
js:
function displayFeeds() {
var feeds = getFeeds();
if(feeds.length == 0) {
//in case we had one form before...
$("#feedList").html("");
$("#introContentNoFeeds").show();
} else {
$("#introContentNoFeeds").hide();
var s = "";
for(var i=0; i<feeds.length; i++) {
s+= "<li><a href='feed.html?id="+i+"' data-feed='"+i+"'>"+feeds[i].name+"</a> <a href='' class='deleteFeed' data-feedid='"+i+"'>Delete</a></li>";
}
$("#feedList").html(s);
$("#feedList").listview("refresh");
}
}
function getFeeds() {
if(localStorage["feeds"]) {
return JSON.parse(localStorage["feeds"]);
} else return [];
}
function addFeed(name,url) {
var feeds = getFeeds();
feeds.push({name:name,url:url});
localStorage["feeds"] = JSON.stringify(feeds);
First of all, create a static collapsible-set div
data-role="collapsible-set"
and give it an id or a class.The JS solution depends on your array's structure, I have created a simple one just for demo.