【发布时间】:2016-05-09 16:18:05
【问题描述】:
我正在尝试使用本地 JSON 信息填充 JQM ListView。但是,不会创建任何列表项。任何帮助,将不胜感激。这是我的代码:
JSON 文件结构:
[
{
"name" : "test"
"calories" : "1000"
"fat" : "100"
"protein" : "100"
"carbohydrates" : "800"
},
{
"name" : "test2"
"calories" : "10000"
"fat" : "343"
"protein" : "3434"
"carbohydrates" : "4343"
}
]
HTML:
<div data-role="page" data-title="Search" id="searchPage">
<ul data-role="listview" data-inset="true" id="searchFood">
</ul>
</div>
JS:
(更新)
$(document).on("pageinit", "#searchPage", function(){
$.getJSON("../JS/food.json", function(data){
var output = '';
$.each(data, function(index, value){
output += '<li><a href="#">' +data.name+ '</a></li>';
});
$('#searchFood').html(output).listview("refresh");
});
});
【问题讨论】:
-
$('#searchFood').html(output).listview("refresh"); -
感谢 Omar - 但仍然没有出现这些更改的列表项:/ 我已更新帖子中的 JS 以反映您的建议。
标签: json listview jquery-mobile