changing <ul> to <ul data-role=“listview”>

▼魔方 西西 提交于 2019-12-10 16:15:40

问题


I have a list which I'm displaying with icons and title only - no JQM formatting. If the screenwidth is below 320 px, I want to convert the list into a JQM <ul data-role="listview"> list.

I can add the attribute via Jquery, but when I call $('.menuList').listview('refresh'); I get the following error:

cannot call methods on listview prior to initialization; attempted to call method 'refresh'

Any clues as to what I'm doing wrong?

Thanks!

Frequent

HTML:

<ul class="menuList">
    <li>
        <div>
            <a href="l" data-transition="slide" rel="external" class="iconViewport icon">
                <span class="menuTitle">GoHere</span>
                <span class="pusher">111</span>
            </a>
        </div>
    </li>
</ul>

Jquery

function enhanceMobile ()
{
    $('.menuList').attr('data-role', 'listview');
    $('.menuList').listview('refresh');
}

回答1:


You can't call .listview('refresh'); on an element that isn't a listview already.

If you just freshly add the data-role, you have to call .listview(); which calls a widget constructor (while .listview('refresh'); calls a refresh method of the widget)

[I already sent you that by e-mail, but it belongs here :) ]



来源:https://stackoverflow.com/questions/5650157/changing-ul-to-ul-data-role-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!