1

有没有人想出任何解决 JQuery Mobile UL 列表视图的方法?

我目前正在使用 JQuery Mobile 1.1.2 Alpha,我所指的错误是一个旧错误:

jQuery Mobile 初始化列表视图的正确方法

我的列表视图如下所示:

<ul data-role="listview" id="store-info">
        <li>My First Store</li>
        <li>48 Big Oak Lane </li>
        <li>Stamford</li>
        <li>CT</li>
        <li>06903</li>
</ul>

我曾尝试使用:

$( "#store-info" ).listview();

还有这个:

$('#stores_main_view').trigger('create');

在以下

<div data-role="content" id="stores_main_view" class="content ui-content" role="main">
<ul data-role="listview" class="ui-listview">
        <li>
    <form class="product-form">
        <ul data-role="listview" id="store-info">
        <li>My First Store</li>
        <li>48 Big Oak Lane </li>
        <li>Stamford</li>
        <li>CT</li>
        <li>06903</li>
</ul>

    </form>
</li>
</ul>
</div>

尝试动态创建列表时,两者都会产生相同的错误:

Uncaught TypeError: Cannot read property 'jQuery1710409190776059404' of undefined 

这个问题有什么好的解决方案吗?

4

2 回答 2

5

The jQuery mobile code (in the method _createSubPages, exactly the one you quoted in the comment) is expecting created controls to be in a .ui-page.

Simply adding the class on the page where the control resides before calling trigger('create') fixed the problem for me.

$('#page-id').addClass('ui-page')

It also works if you do a

$.mobile.loadPage('#page-id')

Hope this helps.

于 2012-08-29T21:38:40.160 回答
0

尝试这个:

$("#nav-panel").load("nav-panel.html", function () {
    $(this).trigger("create");
});
于 2014-09-22T19:16:28.460 回答