Javascript 在';pageshow';
我正在尝试获取一个列表视图,以便在“pageshow”中填充数据。使用Javascript和JQM 1.3.2。 我的html部分是我的页面Javascript 在';pageshow';,javascript,listview,jquery-mobile,Javascript,Listview,Jquery Mobile,我正在尝试获取一个列表视图,以便在“pageshow”中填充数据。使用Javascript和JQM 1.3.2。 我的html部分是我的页面 <div data-role="page" data-theme="b" id="listPlaces"> <div data-role="header" data-position="fixed"> <h4>Header</h4> </div>
<div data-role="page" data-theme="b" id="listPlaces">
<div data-role="header" data-position="fixed">
<h4>Header</h4>
</div>
<div data-role="content">
<div class="content-primary" id="content-primary"></div>
</div>
<div data-role="footer"><h4>Footer</h4></div>
标题
页脚
我正在调用一个外部javascript:
$(document).off("pageinit", "#listPlaces");
$(document).on("pageinit", "#listPlaces", (function parseData(){
var output = '', val;
var output = '<ul data-role="listview" data-autodividers="true" id="listOfPlaces">';
for (val in localStorage) {
if (localStorage.hasOwnProperty(val)) {
place = JSON.parse(localStorage[val]);
output += '<li><div data-role="collapsible">' + '<a href="placeDetail.html?place=' + place["name"] + '">' + place["name"] + '</a><br /><span style="font-size:10px;padding-left:20px">' + place["address"] + '</span><div></li>'
}
}
output += '</ul>';
return output;
}));
$(document).on("pageshow", "#listPlaces", (function() {
alert('in pageshow');
var div = $('#content-primary');
div.output(parseData());
div.find('ul').listview();
}));
$(document).off(“pageinit”,“列表位置”);
$(document).on(“pageinit”,“#listPlaces”,“函数parseData()){
var输出='',val;
var output='';
for(本地存储中的val){
if(localStorage.hasOwnProperty(val)){
place=JSON.parse(localStorage[val]);
输出+='- '+'
'+位置[“地址”]+' '
}
}
输出+='
';
返回输出;
}));
$(文档).on(“pageshow”、“#listPlaces”、(function(){
警报(“在页面显示中”);
var div=$(“#内容主要”);
div.output(parseData());
div.find('ul').listview();
}));
我看到“in pageshow”警报,但没有定义parseData()。我不知道如何解决这个问题。当我将输出发送到console.log时,它看起来很好,我可以将其复制到另一个文件中并正确显示
感谢您的帮助。我是这个网站的新手,所以我试着遵守规则。如果我做错了什么事,请提前道歉。我也搜索了这个网站,找到了这个答案,这很有帮助,但我仍然停留在这个页面显示功能上。
谢谢
div.输出(parseData())
什么是.output()
?-->也许您正在寻找.html()
这应该可以做到:
$(document).off("pageinit").on("pageinit", "#listPlaces", parseData);
$(document).on("pageshow", "#listPlaces", (function() {
alert('in pageshow');
var div = $('#content-primary');
div.html(parseData());
div.find('ul').listview();
}));
function parseData(){
var output = '', val;
var output = '<ul data-role="listview" data-autodividers="true" id="listOfPlaces">';
for (val in localStorage) {
if (localStorage.hasOwnProperty(val)) {
place = JSON.parse(localStorage[val]);
output += '<li><div data-role="collapsible">' + '<a href="placeDetail.html?place=' + place["name"] + '">' + place["name"] + '</a><br /><span style="font-size:10px;padding-left:20px">' + place["address"] + '</span><div></li>'
}
}
output += '</ul>';
return output;
}
$(document).off(“pageinit”).on(“pageinit”,“#listPlaces”,parseData);
$(文档).on(“pageshow”、“#listPlaces”、(function(){
警报(“在页面显示中”);
var div=$(“#内容主要”);
html(parseData());
div.find('ul').listview();
}));
函数parseData(){
var输出='',val;
var output='';
for(本地存储中的val){
if(localStorage.hasOwnProperty(val)){
place=JSON.parse(localStorage[val]);
输出+='- '+'
'+位置[“地址”]+' '
}
}
输出+='
';
返回输出;
}
在页面事件之外声明输出,var output=''代码>你好,奥马尔,谢谢。。。我确实尝试过,但它抱怨我的parseData()函数:“uncaughtreferenceerror:parseData未定义”,然后在页面事件之外定义parseData()。我尝试了所有组合。现在我正在关闭pageinit侦听器,然后声明var output='';以及parseData()函数。我打开pageinit函数,然后打开pageshow函数。消息现在是未捕获的TypeError:Object[Object Object]没有方法“output”。很抱歉我不是想表现得很厚。我想我正在尝试的应该是可行的,我只是不知道我到底是怎么想的。天哪,如果我能投票支持你,我会的!非常感谢!有趣的是,该列表在Chrome中按字母顺序排列,但在Firefox中却没有。。。这是我的下一个任务。。。很高兴从这一次开始继续前进!