0

jQuery Mobile を使用してモバイル アプリを作成していますが、少し問題があります。ajax投稿から取得したデータベースのコンテンツを含むリストを作成したいと思います。

マークアップは次のようになります。

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

<div data-role="content">   
    <ul data-role="listview" data-inset="true" id="Invoices">
        <div id="invoiceList"></div>
    </ul>
</div><!-- /content -->

<div data-role="footer">
    <h4>Page Footer</h4>
</div><!-- /footer -->

これはjQueryです:

$.ajax({
        type: "POST",
        url: "invoices/index.php",
        data: '',
        complete: function(data)
        {
            $('#invoiceList').html(data.responseText);
        }
    });

さて、クエリの結果を間に入れます

  • しかし、どういうわけか、リストのcssは機能しません。

    これを試してみると、うまくいきました:

    <ul data-role="listview" data-inset="true" id="Invoices">
            <li>test</li>
            <li>test</li>
            <li>test</li>
            <li>test</li>
        </ul>
    

    誰かがこれを修正する方法を知っていますか?

    前もって感謝します!

  • 4

    2 に答える 2

    0

    ul要素に要素を追加idしてみてください。要素に要素をclass invoiceList追加していて、書式設定が機能しないためです。lidiv

    <ul data-role="listview" data-inset="true" id="Invoices" class="invoiceList">
    
    </ul>
    
    <script>
    $.ajax({
        type: "POST",
        url: "invoices/index.php",
        data: '',
        complete: function(data)
        {
            $('.invoiceList').html(data.responseText);
        }
    });
    </script>
    
    于 2012-05-04T11:05:20.137 に答える
    0

    jQuery Mobile では、要素を更新するたびに、通常、要素に対してアクションをトリガーするフォローアップ ステップがあります。たとえば、ソートされていないリストに新しいものを追加するときは、呼び出す必要があります

    $('#invoiceList').listview('refresh');
    

    これは、これらの要素をコールバック内の UL に追加した直後に行われcomplete:ます。

    探している動作が生成されない場合は、他にもさまざまな方法を試すことができます。たとえば、.append()を使用する代わりに操作を実行する必要がある場合があります.html()。この種の状況では、そのような使用法がより頻繁に見られます。

    于 2012-05-04T11:28:35.187 に答える