[英]Dynamic content not styled in jQuery Mobile ListView with iScroll
I am trying to build a Cordova/PhoneGap app with the option to "Pull Up" to load dynamic content using ajax call. 我正在尝试构建一个Cordova / PhoneGap应用程序,并选择“上拉”以使用ajax调用加载动态内容。 The remote call runs fine and the dynamic content is added as the child elements to tag.
远程调用运行良好,并且动态内容已添加为要标记的子元素。 I am using iScroll4 plugin for the "pull" option which works fine.
我将iScroll4插件用于“拉”选项,它工作正常。
Initial content in ListView is styled as needed. ListView中的初始内容根据需要设置样式。 But it's not styled for the dynamic content.
但这并不是为动态内容设计的。
When I tried the below things. 当我尝试以下事情时。 The firstone gives some jquery error.
第一个给出了一些jquery错误。
$('#scroller').trigger('pagecreate');
$("#blogList").listview("refresh");
I am not able to provide a fiddle, as the question uses phonegap events. 由于该问题使用了phonegap事件,因此我无法提供提要。
Body Content: 身体内容:
<div data-role="page" id="home">
<div data-role="content">
<div id="wrapper">
<div id="scroller">
<ul id="blogList" data-role="listview"></ul>
<div id="pullUp">
<span class="pullUpIcon"></span><span class="pullUpLabel"></span>
</div>
</div>
</div>
</div>
</div>
I am using deviceready event insteaed of DOMContentLoaded event as its an PhoneGap app. 我正在使用由DOMContentLoaded事件主导的deviceready事件作为其PhoneGap应用程序。
JS Code: JS代码:
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
doBootstrap(); // Bootstraps
getBlogList(); // Initial content loading
loaded();
}
var myScroll, pullUpEl, pullUpOffset, generatedCount = 0;
function pullUpAction() {
$("#blogList").append('<li><a href="#">Generated row ' + (++generatedCount) + '</a></li>');
myScroll.refresh();
}
function loaded() {
pullUpEl = document.getElementById('pullUp');
pullUpOffset = pullUpEl.offsetHeight;
myScroll = new iScroll('wrapper', {
useTransition: true,
topOffset: pullUpOffset,
onRefresh: function() {
if (pullUpEl.className.match('loading')) {
pullUpEl.className = '';
pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Pull up to load more...';
}
},
onScrollMove: function() {
if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) {
pullUpEl.className = 'flip';
pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Release to refresh...';
this.maxScrollY = this.maxScrollY;
} else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match('flip')) {
pullUpEl.className = '';
pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Pull up to load more...';
this.maxScrollY = pullUpOffset;
}
},
onScrollEnd: function() {
if (pullUpEl.className.match('flip')) {
pullUpEl.className = 'loading';
pullUpEl.querySelector('.pullUpLabel').innerHTML = '';
pullUpAction();
}
}
});
document.getElementById('wrapper').style.left = '0';
}
document.addEventListener('touchmove', function(e) {
e.preventDefault();
}, false);
document.addEventListener('DOMContentLoaded', function() {
}, false);
</script>
$("#blogList").append('<li><a href="#">Generated row ' + (++generatedCount) + '</a></li>');
$("#blogList").trigger('create');
$('#blogList').listview('refresh');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.