1

i'm trying to add the item in the listivew as favorite in the favorites list.when i'm clicking on the button(ADD TO FAVORITES) it is not adding the item in the favorites list. This is my Html page for "Favorites list".

I'm creating a dynamic page for displaying the content of the text file. In this page i have a button for "Add to Favorites" when i click on the button a dialog box for asking user "YES" or "NO" to add in favorites if "YES" that particular page has to add to favourites list but i'm not getting any thing.

for Dialog box:

<div data-role="page" id="addToFavoritesDialog">

    <div data-role="header">
        <h1>Add to Favorites?</h1>
    </div>
    <div data-role="content">
    <p>
    <a href="" data-role="button" data-theme="b" class="addToFavoritesButton">Yes!</a>
        <a href="" data-rel="back" data-role="button" class="no">No thank you</a>
    </p>
    </div>
    <div data-role="footer">

    </div>
</div>

Dynamic page: in Js file

$($.mobile.pageContainer).append('<div data-role="page" id="' + seq + '" class="items">
   <div data-role="content">
   </div>
   <div data-role="footer" data-position="fixed">
   <a href="#home" data-icon="home">Home</a>
   <a href="" data-role="button" class="addToFavoritesDiv">Add to Favorites</a>
   </div>
   </div>');

code:

$(".addToFavoritesDiv").live('click', function(event) {
var id=$(this).data('#' + seq);
$.mobile.changePage("addtofav.html", {role:"dialog",data:{"id":id}});
});

$('.addToFavoritesButton').live('vclick', function(event, ui){
var id=$(this).data('#' + seq);
addToStorage(id);
$("#addToFavoritesDialog").dialog("close");
});

$(document).on('click','#fav', function(event, ui){
                //get our favs
                var favs = getStorage();
                var $favoritesList = $("#favoritesList");
                if (!$.isEmptyObject(favs)) {
                    if ($favoritesList.size() == 0) {
                        //$favoritesList = $('<ul id="favoritesList" data-inset="true"></ul>');
                        var s = "<li data-role=\"list-divider\">Favorites</li>";
                        for (var key in favs) {
                            s+= "<li><a href=\"index.html"'+key+'"\">"+favs[key]+"</a></li>";
                        }
                        $favoritesList.append(s);
                        $("#homePageContent").append($favoritesList);
                        $favoritesList.listview();
                    } else {
                        $favoritesList.empty();
                        var s = "<li data-role=\"list-divider\">Favorites</li>";
                        for (var key in favs) {
                            s+= "$("#favoritesList").append('<li><a href="index.html"'+key+'"\">'+favs[key]+'</a></li>');
                        }
                        $favoritesList.append(s);
                        $favoritesList.listview("refresh");
                    }
                } else {
                    // remove list if it exists and there are no favs
                    if($favoritesList.size() > 0) $favoritesList.remove();
                }
            });

Can anyone help me to get the favorites

Thanks in Advance.

0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.