【问题标题】:How would i add more detail to my dynamic created list view with jquery mobile?如何使用 jquery mobile 向我的动态创建的列表视图添加更多细节?
【发布时间】:2013-04-18 13:24:34
【问题描述】:

我将如何在下面的代码中添加 href 和 listview 标头。如果我将它添加到 html 部分,我不会得到列表 下面是html和js

  <script type="text/javascript">
                            $(document).on("pagebeforeshow", "#index1", function() {
                                $(function(){
                                    var items="";
                                    $.getJSON("check-events.php",function(data){
                                    $.each(data,function(index,item) 
                                    {
                                    items+="<li>"+item.enddate+"</li>";
                                     });
                                    $("#contacts").html(items); 
                                    $("#contacts").listview("refresh");
                                    });
                                });
                            });  
                        </script>

            <div data-role="fieldcontain">
                        <ul id="contacts" data-role="listview" data-divider-theme="b" data-inset="true">

            </ul>
            </div>

我把这个放在哪里

<li data-role="list-divider" role="heading">
                List view
            </li>

【问题讨论】:

    标签: jquery html jquery-mobile jquery-mobile-listview


    【解决方案1】:

    让您的 HTML 代码如下所示:

    <ul id="contacts" data-role="listview" data-divider-theme="b" data-inset="true">
        <li data-role="list-divider" role="heading">
            List view
        </li>                           
    </ul>
    

    而不是这个 jQuery 行:

    $("#contacts").html(items);
    

    使用这个:

    $("#contacts").append(items);
    

    这样,在您开始填充之前,标题将位于列表视图中,并且附加功能将在列表视图中添加新内容,而不会删除之前的内容。

    【讨论】:

    • 谢谢你,这很好用。如果你有时间,你会如何为每个列表项添加一个 href。
    • 链接到其他页面
    • 我希望这是你想要的。
  • 我可以将它添加到脚本中,即 items+="
  • "+item.enddate+"
  • "; ?
  • 是的,只需将 #some-page 替换为另一个页面 id,或者如果您使用多个 html 文件,请将其链接到正确的 html 文件。
  • 猜你喜欢
    相关资源
    最近更新 更多
    热门标签