2013-05-14 96 views
0

我正試圖插入數據庫並在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'); 
} 

我能知道這是爲什麼錯誤我得到?

謝謝:)

+0

你沒有將'list'定義爲'var list',所以它在'$ .each()'調用中將會是未定義的... – 2013-05-14 14:19:28

+0

我已經將var list定義爲全局變量 – Beginner 2013-05-14 14:20:51

回答

0

您指定$(list).remove()它將從DOM刪除整個<ul>。你需要使用list.html("");

+0

謝謝你的回答,你能否請你解釋一下你要求我做什麼..因爲我是新手。 – Beginner 2013-05-15 01:49:10

相關問題