将数据插入表时出现未定义的错误

时间:2013-05-14 14:15:45

标签: cordova jquery-mobile

我正在尝试插入db并在listview中显示数据。但是我收到了这个错误。

  05-14 19:43:56.336: E/Web Console(1480): TypeError: Result of expression 'c[0]' [undefined] is not an object. at file:///android_asset/www/jquery_mobile/jquery.mobile-1.2.0.min.js:2

这就是我想要做的事情

function listdata(tx, resultset) {
    div = null;
    list = null;
    var row = null;
    list = $("<ul>").attr({
        'data-role' : 'listview',
        'data-inset' : 'false',
        'id' : 'mylist'
    });
    count = resultset.rows.length;

    $(list).remove();

    $.each(resultset.rows, function(index) {
        row = resultset.rows.item(index);
        var li = '<li><a href="#">' + row['Date'] + '</a></li>';
        list.append(li);
    });
    div = '<div data-role="collapsible" data-inset="false" data-iconpos="right" data-collapsible="true" data-collapsed-icon="arrow-r" data-expanded-icon="arrow-d"><h3>' + row['name'] + '<span class="ui-li-count ui-btn-up-c ui-btn-corner-all" data-iconpos="right">' + count + '</span></h3></div>';

    $(list).appendTo(div).parent().appendTo('[data-role="content"]').end().trigger("create");
    $('div[data-role="collapsible"]').collapsible({
        theme : 'a',
        refresh : true
    }); 
    $('[data-role="listview"]').listview().listview('refresh'); 
}

我能知道为什么会出现这个错误吗?

感谢:)

1 个答案:

答案 0 :(得分:0)

您已指定$(list).remove(),它将从Dom移除整个<ul>。您需要使用list.html("");

相关问题