JQuery Mobile动态Listview过滤器未显示

时间:2013-03-21 18:00:17

标签: jquery ajax html5 css3 jquery-mobile

我是jquery mobile的新手,并以某种方式想出如何成功创建主页,现在是一个子页面(标记为“bible_studies”)以及通过AJAX动态创建的列表。 < / p>

列表看起来很棒,一切正常,除了一件事......过滤器根本没有显示,即使我将数据过滤器设置为true。我尝试了很多我甚至看不到的东西......任何人都可以帮忙吗?

<!DOCTYPE html>
<html>
<head>
<title>Tetelestai Church Mobile | Home</title>    
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css" />
<link href="styles/mobile.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<style>
    .ui-li-thumb, .ui-li-icon {
        left: 1px;
        max-height: 125px; 
        max-width: 125px;
        position: absolute;
        top: 0;
    }
    #wrap{margin-left:50px;}
</style>
</head>
<body id="home">

<!-- Start of first page -->
<div data-role="page" id="home"> 

<h2 id="banner">Tetelestai Church Mobile</h2>
<div data-role="content">   
    <ul data-role="listview" data-inset="true">
        <li><a href="#bible_studies"><img src="../images/star.png" alt="Bible Studies" class="ui-li-icon">Bible Studies</a></li>
        <li><a href="#events"><img src="../images/events.png" alt="Events" class="ui-li-icon">Events</a></li>
        <li><a href="#news"><img src="../images/news.png" alt="Announcements" class="ui-li-icon">Announcements</a></li>
        <li><a href="#map"><img src="../images/map.png" alt="Times And Directions" class="ui-li-icon">Directions</a></li>
        <li><a href="#contact"><img src="../images/contact.png" alt="Contact Us" class="ui-li-icon">Contact Us</a></li>
    </ul>



    <ul data-role="listview" data-inset="true" data-theme="e">
        <li>
            <a href="http://www.tetelestai.org" data-ajax="false" rel="external"><img src="../images/full_screen.png" alt="Full Site" class="ui-li-icon">Full Site</a>
        </li>
    </ul>
    </p>
</div><!-- /content -->

</div><!-- /page -->

<div data-role="page" id="bible_studies">
<header data-role="header" data-theme="b">
    <h1>Tetelestai Bible Studies</h1>
</header>
<article data-role="content" id="bs">
</article>

</div>

 <script type="text/javascript">

//On document ready
$(document).ready(function(){

    //-----------------------------------------------------------------------
    // 2) Send a http request with AJAX http://api.jquery.com/jQuery.ajax/
    //-----------------------------------------------------------------------
    $.ajax({                                      
        url: "../data/series.php",                  //the script to call to get data          
        data: "",                        //you can insert url argumnets here to pass
                                       //for example "id=5&parent=6"
        dataType: 'json',                //data format      
        success: function(data)          //on recieve of reply
        {

            //--------------------------------------------------------------------
            // 3) Update html content
            //--------------------------------------------------------------------
            var list = $('<ul data-role="listview"  data-filter="true" id="series"/>');

            //Loop through each series
            $.each(data, function(key, val) {

                //Create list item
                $('<li><a href="#'+val.series+'"><img src="../assets/video/'+val.series+'/mobile_list_image.jpg" alt="'+val.name+'" /><div id="wrap"><h1>'+val.name+'</h1><p>'+val.description+'</p></div></a></li>').appendTo(list);

            })

            //Add list
            list.listview();
            list.appendTo('#bs');

        }
    });
});

1 个答案:

答案 0 :(得分:2)

您遇到技术错误。当您创建这样的列表变量时:

var list = $('<ul data-role="listview"  data-filter="true" id="series"/>');

您需要立即将其添加到#bs内容中,如下所示:

var list = $('<ul data-role="listview"  data-filter="true" id="series"/>').appendTo('#bs'); 

Final Filter元素不是ul listview的一部分,因为你使用.listview()设置样式,然后将其附加到内容中,不附加filer元素。

我做了一个例子来告诉你我在说什么:http://jsfiddle.net/Gajotres/67dst/

或者,我认为这也可行,只需将其更改为行:

        list.listview();
        list.appendTo('#bs');

到此:

        list.appendTo('#bs');
        list.listview();

这也应该有效,因为在将.listview()应用到内容之前,listviev会附加到内容中。