Jquery mobile Collabsible Listview not updating

Jquery mobile Collabsible Listview not updating

本文关键字:not updating Listview Collabsible mobile Jquery      更新时间:2023-09-26

我正在尝试使用可折叠列表视图进行远程自动完成。它工作完美的普通列表视图,但当我使用折叠列表视图,它不工作。请看演示。http://jsfiddle.net/Q8dBH/8/

下面是我的代码
<div data-role="page" id="startseite">

    <!--<div data-role="main" class="ui-content">!-->
        <div id="one" class="ui-body-d ui-content">
            <ul id="autocomplete" data-role="listview" class="ui-listview-outer" data-inset="true" data-filter="true" data-filter-placeholder="enter 3 or more alphabets...for ex : america " data-filter-theme="a"></ul>
        </div>
     </div>
我javascript

$(document).on("pagecreate", "#startseite", function () {
    $(document).on("click", "li", function () {
        var text = $(this).text();
        $(this).closest("ul").prev("form").find("input").val(text);    });
    $("#autocomplete").on("filterablebeforefilter", function (e, data) {
        var $ul = $(this),
            $input = $(data.input),
            value = $input.val(),
            html = "";
        $ul.html("");
        if (value && value.length > 2) {
            $ul.html("<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>");
            $ul.listview("refresh");
            $.ajax({
                url: "http://gd.geobytes.com/AutoCompleteCity",
                dataType: "jsonp",
                crossDomain: true,
                data: {
                    q: $input.val()
                }
            })
                .then(function (response) {
                $.each(response, function (i, val) {
                    html += "<li data-role='collapsible' data-iconpos='right' data-shadow='false' data-corners='false'><h2>Birds</h2>" + val + "</li>";
                });
                $ul.html(html);
                $ul.listview("refresh");
                $ul.trigger("updatelayout");
            });
        }
    });
});
http://jsfiddle.net/Q8dBH/8/

示例:http://jsfiddle.net/Gajotres/Q8dBH/10/

使用:

$('#startseite').enhanceWithin();

代替:

$ul.listview("refresh");
$ul.trigger("updatelayout");

基本上在jQuery Mobile 1.4之前,每个小部件都有自己的增强方法,而有两种内容范围的增强方法(不幸的是它们并不总是成功)。jQuery Mobile 1.4带来了名为enhanceWithin()的新功能,用于内容增强,特别是如果您正在创建多个动态小部件。在你的情况下,你有两个小部件,listview和可折叠的,所以listview("refresh")是不够的。

更新:

如果你想删除空格,使用以下CSS:

.ui-listview > li h1, .ui-listview > li h2, .ui-listview > li h3, .ui-listview > li h4, .ui-listview > li h5, .ui-listview > li h6 {
    margin: 0 !important;
}

如果控件使用ajax加载,则必须使用:

$(document).on('filterablebeforefilter','#autocomplete',function(e,data){
   ...
})