【发布时间】:2017-07-09 01:31:05
【问题描述】:
我必须使用 jquery mobile 从文本文件中检索值并附加到列表视图中。
我能够从文本文件中检索值,但没有得到预期的输出。
我已经尝试过多次更改 jQuery 中的语法,但没有成功。
我的文本文件有以下数据:
apple.jpe,apple,healthy,
banana.jpe,banana,good,
cherry.jpe,cherry,tasty,
cranberry.jpe,cranberry,sour,
grape.jpe,grape,wine,
orange.jpe,orange,citric
<body>
<div data-role="page" id="pageOne">
<div data-role="content" id="header">
This is my list view where I want to load content dynamically from file
<ul data-role="listview" data-inset="true" id="list">
</ul>
</div>
</div>
<script>
$(document).on("pageinit", "#pageOne", function(){
$.get("info.txt",function(data){
var items=data.split(',');
for(var i=0;i<items.length;){
$("#header ul").append('<li>'+'<a href="#">');
creating image element which is a thumb nail in list view
var img = $('<img />').attr({
'src': 'img/'+items[i],
'width': 50
}).appendTo('#list');
creating heading element to list view
$('#list').append('<h2>'+items[i+1]+'</h2>');
creating para element to list view
$('#list').append('<p>'+items[i+2]+'</p>'+'</a>'+'</li>');
i=i+3;
}
I have tried refresh for list view
$('#list').listview('refresh');
});
});
</script>
</body>
【问题讨论】:
标签: jquery jquery-mobile