在jquery mobile上刷新页面

时间:2013-12-16 09:38:31

标签: jquery jquery-mobile jquery-mobile-listview browser-refresh

我在jquery mobile中创建一个动态列表,基于我本地存储中的JSON文件(不是PHP文件,只是本地存储),每次根据已删除的项目转到该页面时,列表都会重建添加到它,它全部在jquery移动,但是,当我回到列表时,我必须手动按刷新来更新它,我尝试使用

$('#myListPage').on('pageshow', function(){
  window.location.reload(true);
});

然而,它似乎没有做任何事情,如果我手动按F5或刷新,一切都很好。

这是每次创建列表的方式:

function run2() { 
  peopleList();
  $("#list").listview("refresh").trigger("create");
};


function peopleList() {
    $("#peopleList ul li").each().remove();
    for (i = 0; i < cars.length; i++) {
        if (cars[i].availability == "true") {
            $("#peopleList ul").append('<li value = ' + i + ' id="colas">' + '<div  data-role="collapsible" data-theme="b" data-content-theme="a">' + '<h3>' + cars[i].carName + '</h3>' + '<span data-inset="true">' + '<img src="' + cars[i].imageSrc + '" style="width:auto; margin:0px auto" id="imgcar"/>' + '<h2>' + cars[i].carModel + ", " + cars[i].gear + "</h2> " + '</span>' + '<input type="button" value="Select this car" data-icon="check" onclick="aval(' + i + ')"/></div>' + '</li>');
        }
    }
}

很抱歉,如果它有一个简单的答案,我是新来的,我正在努力学习,但我的指示只是使用本地存储,而不是PHP,非常感谢你们。

编辑:

这是代码的html

<div data-role="page" id="catalog">
  <div data-role="header" data-theme="a">
    <h1>Choose your car!</h1>
  </div>
  <div data-role="content" id="peopleList" class="ui-grid-b">
    <ul data-role="listview" data-inset="true" id="list" class="ui-block-a">
    </ul>
    <div class="ui-block-c">
      <canvas id ="myCanvas"  style="margin-left:100px; width:300px; height:300px"></canvas>
    </div>
    <div class="ui-block-b"></div>
  </div>
  <div data-role="footer" data-position="fixed"  class="copyright"><h2> &copy  </h2></div>
</div>

3 个答案:

答案 0 :(得分:1)

您可以通过以下方式刷新列表视图:

$('#peopleList').listview('refresh');  

在此处查看文档:{​​{3}}

答案 1 :(得分:0)

在互联网的黑暗角落进行了长时间的搜索之后,我发现了一个可以解决这个问题的命令,我不知道它意味着什么,或者它是如何做到的但它有效。

var path = location.pathname;
var filename = path.match(/.*\/([^/]+)\.([^?]+)/i)[1]+".html";
location.href= filename;

答案 2 :(得分:-1)

如何使用:

$(document).ready(function(){
    //window.location.reload(true);
    location.href = 'url';
});