0

リストビューに「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="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();
 }));

「in pageshow」アラートが表示されますが、parseData() が定義されていません。これを修正する方法がわかりません。出力を console.log に送信すると問題なく表示され、それを別のファイルにコピーして正しく表示することができます。

どんな助けでも大歓迎です。私はこのサイトに投稿するのが初めてなので、ルールに従おうとしました。私が何か間違ったことをした場合は、事前に謝罪してください。また、サイトを検索したところ、この回答が見つかりました。スタイルをjqueryモバイルでリストビューに更新する方法は? これは役に立ちましたが、私はまだこのページ表示機能にこだわっています。ありがとう

4

1 に答える 1

0

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;
}
于 2013-10-24T06:43:33.427 に答える