jQuery Mobile的设置ListView控件的属性 [英] jQuery Mobile setting an attribute of a ListView

查看:167
本文介绍了jQuery Mobile的设置ListView控件的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ELLO StackOverflowers。

'Ello StackOverflowers.

所以这是我的情况:
我填充的ListView 使用的localStorage 。一切工作的填充ListView和提神它。但是!

So this is my scenario: I populate a ListView using localStorage. Everything working populating that listview and "refreshing" it. BUT!

现在我想添加一个搜索栏,如果超过5个元素被添加到的ListView 。这是我目前的code(没有工作):

Now I want to add a search bar if more than 5 elements are added to the ListView. This is my current code (which is not working):

if (resultLength > 5)
{
    // alert('5 or more elemnts found.');
    $("#ConnectionList").attr("data-filter", true);
    $("#ConnectionList").attr("data-filter-placeholder", "Search...");
}

当我取消注释警报,它正确地触发。添加 .listview('刷新')两行的背后似乎并没有擦出火花。

When I uncomment the alert, it fires correctly. Adding .listview('refresh') behind the two lines does not seem to work either.

我在做什么错了?

感谢您提前。

推荐答案

可惜,这是行不通的。 jQuery Mobile的 将无法动态地添加过滤器,以现有的列表视图。

Unfortunately this is not going to work. jQuery Mobile will fail to dynamically add filter to an existing listview.

但有一个变通方法。在您填充元素的列表视图的计数您要填充,如果数量为5个以上删除当前ListView和追加在同一个地方新的。这是另一种奇怪的东西,如果你创建一个列表视图从头开始(在考虑过滤器),过滤器将被成功生成。

But there's a workaround. Before you populate your listview count number of elements you are trying to populate, if number is 5 or more remove current listview and append new one at the same place. This is another strange thing, if you create a listview from scratch (with filter in mind), filter is going to be successfully generated.

我做了一个例子给你: http://jsfiddle.net/Gajotres/SS7vJ/

I made an example for you: http://jsfiddle.net/Gajotres/SS7vJ/

$(document).on('pagebeforeshow', '#index', function(){       
    $('<ul>').attr({'id':'test-listview','data-role':'listview', 'data-filter':'true','data-filter-placeholder':'Search...'}).appendTo('#index [data-role="content"]');
    $('<li>').append('<a href="#">Audi</a>').appendTo('#test-listview');
    $('<li>').append('<a href="#">Mercedes</a>').appendTo('#test-listview');
    $('<li>').append('<a href="#">Opel</a>').appendTo('#test-listview');
    $('#test-listview').listview().listview('refresh');
});

另外,不要忘记调用.listview(两次,第一次没有刷新参数,并第二次与一个刷新参数没有它,你将收到此错误:

Also don't forget to call .listview( twice, first without refresh parameter, and second time with a refresh parameter. Without it you will receive this error:

cannot call methods on listview prior to initialization

您可以找到更多关于这个 <一个这个问题href=\"http://www.gajotres.net/jquery-mobile-and-how-to-enhance-the-markup-of-dynamically-added-content/\"相对=nofollow>文章 ,是透明这是我的个人博客。或者发现它的 这里 。寻找所谓的章节:标记增强问题

You can find more about this problem in this ARTICLE, to be transparent it is my personal blog. Or find it HERE. Look for the chapter called: Markup enhancement problems.

这篇关于jQuery Mobile的设置ListView控件的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆