簡體   English   中英

無法使.listview('refresh')和.trigger(“ updatelayout”)工作

[英]Not able to get .listview('refresh') and .trigger( “updatelayout”) working

我正在使用Ajax檢索數據並填充列表。 但是我無法讓jQuery Mobile添加樣式列表所需的類,或者如果我進行新搜索(舊結果仍在列表中)則刷新列表。

我已經在Stack上找到了很多類似的Q / A,但是沒有一種解決方案有效。 我尚未實現在jQuery Mobile上找到的整個解決方案,但是我認為這應該仍然有效嗎?

我建立清單錯誤嗎? 我在這里擺弄

// HTML
<ul id="brandList" class="front" data-role="listview" data-inset="true"></ul>

// JS
var el = Part.mainSearchResult();

$(response.brands).each(function(){
    var brand = $(this)[0];
    var url = '/brand?id=' + brand.id;
    var li = $(el.brand).clone();

    $(li).find('a').prop('href',url);
    $(li).find('a').text(brand.name);
    $('#brandList').append(li);
});

$('#brandList').listview('refresh');
$('#brandList').trigger( "updatelayout");

Fiddle中的代碼有誤,CSS部分中包含UL。

在CSS部分中,而不是HTML中:

<ul id="mylist" class="front" data-role="listview" data-inset="true"></ul>

似乎可以正常使用,並且正在將這些類添加到UL中。

更新了JS小提琴

編輯:

您需要調用$('#mylist').listview( "refresh" ); 測試功能內部

新產品

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM