我在使用 Android 4.0.3+JQM+Phonegap 时没有遇到任何问题。昨天我在Android 4.1上测试,发现那些动态生成的ListView有时会给我重复的结果。例如,我使用以下代码生成一个 ListView 来显示今天的日期:
<ul data-role="listview" data-inset="true" data-theme="c"
data-divider-theme="d" id="todayvalue">
</ul>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var today = new Date();
var dayofmonth = today.getDate();
var dayofweek = today.getDay();
var year = today.getFullYear();
var month = today.getMonth();
var myDays= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
var m_names = ["January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December"];
$('#todayvalue').append('<li>Today is '+ myDays[dayofweek]+ ', '+year+'-'+m_names[month]+'-'+dayofmonth+'</li>');
$('#todayvalue').listview('refresh');
}
它以前完全没有问题。但现在它会生成两个相同的行。
怪谁?
更新:我已将项目上传到https://github.com/ysongfinance/520Toll。
经过进一步调试,我发现onDeviceReady() 被调用了两次,但其中一个看起来很奇怪:
07-05 20:42:31.368:I/Web 控制台(825):########in OndeviceReady at file:///android_asset/www/js/updatetoll.js:4 07-05 20:42 :31.488:I/Web 控制台(825):########in OndeviceReady at null :4
看看第二个调用“在 OndeviceReady 中为 null”,那个“null”是什么意思?