0
<!DOCTYPE html>
<head>
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css">


</head>
<body>
    <div data-role="page" id="twitterPage" data-theme="a">

        <div data-role="content">
            <ul id="tweet-list" data-role="listview" data-inset="true" data-filter="true" >

            </ul>
        </div>
    </div>

    <script type="text/javascript">
        $.ajax({
            url: "http://192.168.1.60/json_android/getItemData.php",
            jsonpCallback: 'item',
            contentType: "application/json",
            dataType: 'jsonp',
            success: function(data) {
                console.log(data);

                var markup = "";
                $.each(data.list, function(i, elem) {
                    var $template = $('<li>    <div class=ui-grid-a>   <div class=ui-block-a>  </div>  <div class=ui-block-b>    </div>  </div>   </li>');

                    $template.find(".ui-block-a").append('<a href=#  id=' + elem['itemId'] + '>' + elem['itemId'] + '</a>');
                    $template.find(".ui-block-b").append("<input type=text />")


                    markup += $template.html();

                });
                $("#tweet-list").append(markup).listview("refresh", true);

                // Transition to the Twitter results page.
                //$.mobile.changePage($("#twitterPage"));
            },
            error: function(request, error) {
                alert(error);

            }
        });



        $('#tweet-list').on('click', 'a', function(event) {
            event.preventDefault();
            console.log($(this).closest('div').next('.ui-block-b').find('input').val());
        });

   </script>
</body>

我尝试使用上面的代码用数据填充列表视图。由于stackoverflow,它可以正常工作,但是当我在Android平板电脑上尝试它时它不起作用。它只显示列表视图的搜索栏。

4

1 回答 1

1

试试这个添加你的脚本 $(document).on('pageshow',function(){});

 <!DOCTYPE html>
 <head>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css">
 </head>
<body>
<div data-role="page" id="twitterPage" data-theme="a">
  <script type="text/javascript">
  $(document).on('pageshow',function(){
    $.ajax({
        url: "http://192.168.1.60/json_android/getItemData.php",
        jsonpCallback: 'item',
        contentType: "application/json",
        dataType: 'jsonp',
        success: function(data) {
            console.log(data);

            var markup = "";
            $.each(data.list, function(i, elem) {
                var $template = $('<li>    <div class=ui-grid-a>   <div class=ui-block-a>  </div>  <div class=ui-block-b>    </div>  </div>   </li>');

                $template.find(".ui-block-a").append('<a href=#  id=' + elem['itemId'] + '>' + elem['itemId'] + '</a>');
                $template.find(".ui-block-b").append("<input type=text />")


                markup += $template.html();

            });
            $("#tweet-list").append(markup).listview("refresh", true);

            // Transition to the Twitter results page.
            //$.mobile.changePage($("#twitterPage"));
        },
        error: function(request, error) {
            alert(error);

        }
    });



    $('#tweet-list').on('click', 'a', function(event) {
        event.preventDefault();
        console.log($(this).closest('div').next('.ui-block-b').find('input').val());
    });
});
  </script>
    <div data-role="content">
        <ul id="tweet-list" data-role="listview" data-inset="true" data-filter="true" >

        </ul>
    </div>
</div>


</body>
于 2013-10-29T12:00:11.917 回答