我正在尝试从数据库生成列表视图。我正在从MySQL数据库中检索,刷新listview后,CSS或设计没有更新。
单击来自phonegap
中其他页面的列表项时会生成列表视图使用Javascript:
$('#facilityListView li').live('click',function(){
var selectedFacility = $(this).attr('name');
var appendFacilityType = $('#facilitySpecificType');
var fContent = "";
$.ajax({
type:'GET',
data: {sFacility:selectedFacility},
dataType: 'jsonp',
jsonp: 'jsoncallback',
timeout: '5000',
url: 'http://localhost/getSpecificFacilityCategory.php',
success:function(data){
$.each(data,function(f,fitem){
fContent += '<li><a href="#">' + fitem.FacilityName+ '</a></li>';
});
appendFacilityType.empty().append(fContent).listview("refresh");
},
error: function(){
alert("failed");
console.log(data);
}
});
});
修正版
$('#facilityListView li').on('click', 'li' ,function(){
var selectedFacility = $(this).attr('name');
var appendFacilityType = $('#facilitySpecificType');
var fContent = "";
$.ajax({
type:'GET',
data: {sFacility:selectedFacility},
dataType: 'jsonp',
jsonp: 'jsoncallback',
timeout: '5000',
url: 'http://localhost/getSpecificFacilityCategory.php',
success:function(data){
$.each(data,function(f,fitem){
fContent += '<li><a href="#">' + fitem.FacilityName+ '</a></li>';
});
appendFacilityType.empty().append(fContent).listview("refresh");
},
error: function(){
alert("failed");
console.log(data);
}
});
});
答案 0 :(得分:0)
对于遇到相同问题的其他人,此问题是由.live
函数deprecated in JQuery 1.7支持.on
函数的事实引起的。
正确的解决方案如下:
$('#facilityListView li').on('click', 'li' ,function(){
var selectedFacility = $(this).attr('name');
var appendFacilityType = $('#facilitySpecificType');
var fContent = "";
$.ajax({
type:'GET',
data: {sFacility:selectedFacility},
dataType: 'jsonp',
jsonp: 'jsoncallback',
timeout: '5000',
url: 'http://localhost/getSpecificFacilityCategory.php',
success:function(data){
$.each(data,function(f,fitem){
fContent += '<li><a href="#">' + fitem.FacilityName+ '</a></li>';
});
appendFacilityType.empty().append(fContent).listview("refresh");
},
error: function(){
alert("failed");
console.log(data);
}
});
});