1

I have tried a ton of solutions and am in the hair pulling stage, if anyone can help it would be deeply appreciated... TIA. :)

I am attempting to display the contents of a JSON array in my HTML with proper styling in place. Here is the JSON array I am loading: http://highendwholesale.com/json.php

Here is the result I get when using the code below, as you can see it loads fine but without styling -- if anyone can help me get this working I would be grateful: http://highendwholesale.com/test.php

<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $.ajaxSetup({ cache: false });
    $.getJSON("json.php", function(data){
        $('ul#myInventory').empty();

        $.each(data, function(index, d){           
            $('ul#myInventory').append("<li><a href='#'><img src='http://highendwholesale.com/listings/"+d.CID+"/thumb/1.jpg' height='80' width='80' alt='"+d.CID+"' /><h2>"+d.title+"</h2><p>"+d.blurb+"</p></a></li>");
        });         
        $('ul#myInventory').trigger("create");          
    }).error(function(jqXHR, textStatus, errorThrown){
        alert("error occurred!");
    });
    $('ul#myInventory').listview('refresh');         
});
</script>
</head>
<body>
<div data-role="page" id="index" data-theme="d">

    <div data-role="header">
        <h1>Inventory</h1>
    </div><!-- /header -->

<div data-role="content">   
    <div id="inventory">
        <ul data-role='listview' id='myInventory' data-inset='true' class='ui-listview ui-listview-inset ui-corner-all ui-shadow'></ul>
    </div>
</div><!-- /content -->

</div>
</body>
</html>
4

1 回答 1

0

首先在您的html中准备ul。然后将 li 添加到这个 ul。在您对 listview 的 ajax 调用之后添加它。

$('ul#yourList').trigger("create");

更新 HTML

<div data-role="content">   
    <div id="inventory">
        <ul data-role='listview' id='myInventory' data-inset='true' class='ui-listview ui-listview-inset ui-corner-all ui-shadow'></ul>
    </div>
</div><!-- /content -->

更新查询

$(document).ready(function(){
    $.ajaxSetup({ cache: false });
    $.getJSON("json.php", function(data){
        $('ul#myInventory').empty();

        $.each(data, function(index, d){           
        $('ul#myInventory').append('<li data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-icon="arrow-r" data-iconpos="right" data-theme="c" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-li-has-thumb ui-btn-up-c">'+
            '<div class="ui-btn-inner ui-li">'+
                '<div class="ui-btn-text">'+
                    '<a href="#" class="ui-link-inherit">'+
                        '<img src="http://highendwholesale.com/listings/'+d.CID+'/thumb/1.jpg" height="80" width="80" alt="'+d.CID+'" class="ui-li-thumb">'+
                        '<h2 class="ui-li-heading">'+d.title+'</h2>'+
                        '<p class="ui-li-desc">'+d.blurb+'</p>'+
                    '</a>'+
                '</div>'+
                '<span class="ui-icon ui-icon-arrow-r ui-icon-shadow">&nbsp;</span>'+
            '</div>'+
        '</li>');
    });

        $('ul#myInventory').trigger("create");          
    }).error(function(jqXHR, textStatus, errorThrown){
        alert("error occurred!");
    });
    $('ul#myInventory').listview('refresh');         
});
于 2013-06-10T04:09:15.983 回答