【问题标题】:jQuery Mobile JSON formattingjQuery Mobile JSON 格式
【发布时间】:2012-02-01 14:39:09
【问题描述】:
【问题讨论】:
标签:
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。