简体   繁体   English

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

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

I'm using Ajax to retrieve data and populate my list. 我正在使用Ajax检索数据并填充列表。 But I'm not able to get jQuery Mobile to add the classes needed to style my list, or refresh the list if I do a new search (old results is still in list). 但是我无法让jQuery Mobile添加样式列表所需的类,或者如果我进行新搜索(旧结果仍在列表中)则刷新列表。

I've found plenty of similar Q/A's here on Stack, but none of the solutions work. 我已经在Stack上找到了很多类似的Q / A,但是没有一种解决方案有效。 I've not implemented the entire solution found over at jQuery Mobile , but I believe this should work anyway? 我尚未实现在jQuery Mobile上找到的整个解决方案,但是我认为这应该仍然有效吗?

Am I building the list wrong? 我建立清单错误吗? I have a fiddle here 我在这里摆弄

// 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");

The code in your Fiddle had a mistake, you had the UL in the CSS section. Fiddle中的代码有误,CSS部分中包含UL。

Was in the CSS Section, not HTML: 在CSS部分中,而不是HTML中:

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

Seems to be working and is adding the classes to the UL. 似乎可以正常使用,并且正在将这些类添加到UL中。

Updated JS Fiddle 更新了JS小提琴

EDIT: 编辑:

You need to call $('#mylist').listview( "refresh" ); 您需要调用$('#mylist').listview( "refresh" ); inside the test function 测试功能内部

NEW FIDDLE 新产品

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM