【问题标题】:jQuery Mobile JSON formattingjQuery Mobile JSON 格式
【发布时间】:2012-02-01 14:39:09
【问题描述】:

我有一个由 JSON 生成的列表视图,但我不知道如何动态创建 div 标签来保存所有列表项元素。它看起来像一个没有任何 CSS 格式的列表。我不知道我做错了什么。这是问题页面:http://mbeta.calvaryccm.com/#teachings 这就是我希望它看起来的样子:http://mbeta.calvaryccm.com/ 我不知道如何格式化我的列表视图以显示我需要的内容。

【问题讨论】:

    标签: jquery json listview jquery-mobile jsonp


    【解决方案1】:

    好吧,我不能在这里写完整的代码,但我相信你需要这样写:

    // i assume your JSON response is stored in data object
    // following is the loop which reads the data object ,gets the value and append it to the `<li>` of `<ul>`
    

    var list= $("").attr("id","list"); //在jquery中动态创建一个新的ul元素

    for(var i=0;i<data.length;i++)
    {
    
    var li=$("<li/>").html(data[i].name); // get the value of name in JSON and put it in newly created li ,(getting value will depend on your json string format)
    
    $("#list").append(li); //append li to ul of id list
    
    }
    
    $(body).append(list); // append the list to anywhere you want, i am appending it to body.
    

    【讨论】:

      【解决方案2】:

      如果您是动态添加内容(通过 ajax),则需要初始化或刷新列表视图:

      $('#mylist').listview();
      // or if you already have a listview that you are appending to
      $('#mylist').listview('refresh');
      

      请参阅页面底部的Calling the listview plugin

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-12
        • 1970-01-01
        • 2011-12-15
        • 2014-01-02
        • 1970-01-01
        • 2018-02-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多