1

リスト アイテムのタップ イベントによってトリガーされる (Google Feeds API を使用した) フィード アイテムのリストの生成に問題があります。ページの読み込み時に関数を呼び出すことができ、うまく機能します。ただし、「タップ」イベントで関数を呼び出そうとすると、空白のページが生成されます。

イベントをトリガーしたいリスト項目は次のとおりです(「タップ」イベントを呼び出しています):

<li id="welstech" class="listFeeds">
        <a href="#">
         <img src="_images/welstech-logo-db.jpg" alt="WELSTech" />       
         <h2>WELSTech Podcast</h2>
         <p>Discussions about Tech & Ministry</p>
        </a>
       </li>

HTMLページの下部に配置したスクリプトは次のとおりです。

    <script type="text/javascript>
    $(document).on('tap', '.listFeeds', function() {
    listAudioPosts("http://feeds.feedburner.com/welstech");
});
    </script>

呼び出す関数は次のとおりです。

function listAudioPosts(feedurl){
    google.load("feeds", "1");
console.log("I'm still going 1");
    function initialize() {
console.log("I'm still going 2");
      var feed = new google.feeds.Feed(feedurl);
      feed.setNumEntries(10)
      var output = '<ul data-role="listview" data-split-icon="info">';
      var name = "welstech";
      feed.load(function(result) {
          if (!result.error) { 
              for (var i = 0; i < result.feed.entries.length; i++) {
                  var entry = result.feed.entries[i];
                  var mediaGroups = result.feed.entries[i].mediaGroups[0].contents[0];
                  var stripContentSnippet = entry.contentSnippet.replace(/[^a-zA-Z 0-9.:-]+/g,'');
                  var stripaContentSnippet = stripContentSnippet.replace('lt--pagingfilter--gt','');
                  output += '<li>';
                  output += '<a href="#">';
                  output += '<h2>' + entry.title + '</h2>';
                  output += '<p>' + stripaContentSnippet + '</p>';
                  output += '</a>';
                  output += '</li>';
                } // loop through all the feeds and create li elements
            } // end of if statement
            output += '</ul>';
            $("#testtouchoutput").html(output).trigger('refresh');
            $.mobile.changePage("#test");
        }); // end feed.load (function(result)
    } // end initialize function
    google.setOnLoadCallback(initialize);   
}

以下を参照して、htmlページの下部にあるこのスクリプトを使用して、ページの読み込み時に関数を呼び出すことができるため、関数が機能することはわかっています。また、そのサブ関数の前に console.log 出力が表示されますが、その後の出力は表示されないため、関数がサブ関数 initialize() まで到達することもわかっています。

<script type="text/javascript">
    listAudioPosts("http://feeds.feedburner.com/welstech");
</script>

したがって、ホームページが読み込まれると、関数が実行され、生成したいリストにページが更新されます...「タップ」イベントで生成したい場合を除きます。

私はかなり新しいjqueryプログラマーなので、それは明らかなことだと確信しています。私は何が欠けていますか?

ありがとう。

4

1 に答える 1

0

.on を閉じていない場合は、次のようにしてください。

<script type="text/javascript>
    $(document).ready(function() {
        var timeTouched;
        $('.listFeeds').bind('touchstart', function() {
            timeTouched = new Date().getTime();
        }
        $('.listFeeds').bind('touchend', function() {
            if (new Date().getTime() - timeTouched < 200) { // Ended touch within 200 milliseconds, counts as a tap
                listAudioPosts("http://feeds.feedburner.com/welstech");
            }
        });
    });
</script>

スクリプトが .listFeeds 要素が定義されている場所の上にあることを確認し、$(document).ready() 部分を含めます。そうしないと、イベントをその要素にバインドできなくなります。

更新: タップはイベントではないようで、潜在的な解決策で更新されました。

更新 2: .on の代わりに .bind を試しています。

于 2012-08-19T04:11:04.990 に答える