0

我有一个列表视图,每个列表都循环出一个列表。它从远程服务器上的数据库中获取。它工作正常,但我想基于点击让用户转到另一个页面,我需要他们点击的东西的 id 跟随到带有本地存储的那个页面。

所以我编码了这个:

使用 THIS 获取变量并将其放在本地存储中单击事件不起作用。

var ss = "http://localhost/arenaapp/services/";

var arenas;

$('#ListArenasPage').on('pageshow', function(event) {
        getarenaList();
});

function getarenaList() {
    var country = window.localStorage.getItem("country");
    $.getJSON(ss + 'getarenas.php?id=' + country, function(data) {
        $('#arenaList li').remove();
        arenas = data.items;
        $.each(arenas, function(index, arena) {
            $('#arenaList').append('<li><a href="">' +
                    '<img src="pics/' + arena.picture + '"/>' +
                    '<h4>' + arena.arenaName + '</h4>' + '<p id="category">Club:' + arena.arenaClub + '</p>' +
                    '<p>Capacity:' + arena.arenaCapacity + '</p>' +
                    '<span class="ui-li-count">' + arena.id + '</span></a></li>');
        });
        $('#arenaList').listview('refresh');
    });
}


$('#arenaList').on ('click', function(){
        window.localStorage.setItem("currentid", arena.id);
        document.location.href = "arenaDetails.html";
    });

我知道这有很多问题。我无法设置项目,因为 arena.id 未设置。它只在我猜的函数中设置?但是我怎样才能使 arena.id 最终出现在 localstorage 项(我的代码的最后一个块)中。我猜我必须使用 THIS 或类似的东西。但我是 jquery 的新手,你会如何做这个工作?

4

1 回答 1

0

尝试这个 -

$('#arenaList').on('click','li', function(){
   window.localStorage.setItem("currentid", $(this).find('.ui-li-count').text());
   document.location.href = "arenaDetails.html";
});
于 2013-06-13T11:16:54.260 回答