我正在尝试开发一个应用程序,并且我正在将 jQuery mobile 用于 UI。有人知道如何使用 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);