-1

我在通过单击另一个页面上存在的另一个 li 来删除 li 时遇到问题.. 并且删除 li id 存在于 localStorage 变量中..

这是同一页面上的两个 div。第一个 li 代码是

<div data-role="page" id="wishListPage" data-add-back-btn="true">
            <div data-role="header" data-position="fixed">
                <header id="mainHeader" align="center">
                    <a href="#"><img src="images/logoName.png" /> </a>
                </header>
            </div>
            <div data-role="content" data-theme="a" id="wishProducts">
                <ul id="wishList" data-role="listview"></ul>
            </div>
    </div>

li 设置哪些值来自数据库的属性rs.rows.item(i).id

$("#wishList").append('<li id="'+rs.rows.item(i).id+'"><a href="index.html#removeProductDialogPage" data-role="button" data-rel="dialog" data-transition="slide" data-ajax="false" onClick=saveValuesInLocalStorage("'+rs.rows.item(i).id+'","'+rs.rows.item(i).productName+'","'+rs.rows.item(i).imageName+'","'+rs.rows.item(i).vendorImageName+'","'+rs.rows.item(i).fixedPrice+'","'+rs.rows.item(i).finalPrice+'","'+rs.rows.item(i).authorName+'","'+rs.rows.item(i).sharingUrl+'");>' +
                '<img src='+rs.rows.item(i).imageName+' id="itemImage"/>'+
                '<span id="dataName"><h4>'+pName+'</h4></span>' +
                '<p><span id="dataAuthorName">'+aName+'</span></p>' +
                '<p><span id="itemRsPrice">Rs.&nbsp;&nbsp;</span><span id="itemStrikePrice"><strike>'+rs.rows.item(i).fixedPrice+'</strike></span>&nbsp;&nbsp;<span id="itemPrice">'+rs.rows.item(i).finalPrice+'</p></span>'+'<img src='+rs.rows.item(i).vendorImageName+' id="itemSite"/></a></li>');
        }
        $("#wishList").listview("refresh");

这里wishList 是ul 的id.. 存储在localStorage 中的代码是..

function saveValuesInLocalStorage(productUrl, productName , productImageName , vendorImage , fixedPrice, finalPrice, authorName,sharingUrl){
    localStorage.sharingUrl  = sharingUrl;
    localStorage.productUrl = productUrl;
    localStorage.productName  = productName;
    localStorage.imageName = productImageName;
    localStorage.vendorImage = vendorImage; 
    localStorage.fixedPrice = fixedPrice;
    localStorage.finalPrice  = finalPrice;
    localStorage.authorName = authorName;
}

现在我想删除有 id 的 lilocalStorage.productUrl

对话页面是:

<div data-role="content" data-theme="a">
            <ul name="options" id="options" data-role="listview">
                <li>
                    <a href="#" data-theme="a" data-ajax="false" onClick=" removeInfoDatabase()">
                        <p><span id="itemName"><h4>Remove from wish List</h4></span></p>
                    </a>
                </li>
                <li>
                    <a href="javascript:void(0);" data-theme="a" data-ajax="false"  onclick="openWebLink()">
                        <p><span id="itemName"><h4>Go to Store</h4></span></p>
                    </a>
                </li>
             </ul>
</div>

以下代码显示了 phonegap SQLite 代码。并且 removeInfoDatabase() 函数是..

function removeInfoDatabase (){
    db.transaction(removeElement, removeError, removeSuccess);
}

function removeError(err){
    console.log("Error processing SQL: "+err.code);
    alert("couldn't remove from wish list");
}
function removeSuccess(){
    var elem =document.getElementById(localStorage.productUrl);
    elem.parentNode.removeChild(elem);
//  $("#"+localStorage.producturl).remove();
//  var mm = $("#"+localStorage.producturl).html();
//  alert(""+mm);
    $("#wishList").listview("refresh");
    alert("item is removed successfully");
    history.back();
}
function removeElement(tx){
    tx.executeSql('CREATE TABLE IF NOT EXISTS itemDetail (id unique, productName , imageName, vendorImageName , fixedPrice , finalPrice , authorName , sharingUrl)');
    tx.executeSql('DELETE  from itemDetail where id="'+localStorage.productUrl+'"');
}

现在我如何在单击“从愿望清单中删除”后删除愿望清单 li 请帮助我..请提前致谢..

4

1 回答 1

1

假设这两个页面在同一个站点上(这样它们共享同一个localStorage对象),您最简单的选择是setTimeout()在将要删除元素的页面上使用,以轮询本地存储是否存在 ID。

function pollStorage() {
    var id = localStorage.id;
    if (typeof id !== 'undefined') {
        delete localStorage.id;
        $(id).remove();
    }
    setTimeout(pollStorage, 100);
}

pollStorage();
于 2012-06-29T13:03:07.967 回答