0

我正在尝试从数据库中生成一个列表视图。我从 MySQL 数据库中检索,刷新列表视图后,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);
        }
    });
 });
4

1 回答 1

0

对于遇到同样问题的其他人来说,这个问题是由于该.live函数在 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);
        }
    });
 });
于 2013-07-08T05:51:20.983 回答