0
我controller.js數據一起使用的角度圖表的離子如下:如何從數據庫中獲取
.controller('dashboardCtrl', function($scope,TestMethod,$cordovaSQLite) {
var dis_stime = [];
var dis_steps = [];
$scope.select = function() {
console.log("check1");
var lastSynced = localStorage.getItem('lastSynced');
if (lastSynced != undefined) {
console.log("check2");
// alert("lastSynced time is "+lastSynced);
// alert("query written");
try {
db = $cordovaSQLite.openDB({name:"health.db",location:'default'});
// alert("inside create");
} catch (error) {
alert(error);
}
lastSynced = lastSynced * 1000000;
startTime = lastSynced - (86400 * 1000000000);
for (var i = 1; i < (PERIOD +1); i++) {
$cordovaSQLite.execute(db,"SELECT SUM(stepcount) AS total FROM activity WHERE startTime BETWEEN ? AND ?", [startTime,lastSynced])
.then(function (resultSet)
{
dis_stime[i] = lastSynced;
dis_steps[i] = resultSet.rows.item(0).total;
alert("total is " + resultSet.rows.item(0).total);
// alert("Total is : " +resultSet.rows.item(0).total);
// alert("total entries" + resultSet.rows.length);
}, function(error) {
alert('SELECT error: ' + error.message);
});
lastSynced = startTime;
startTime = startTime - (86400 * 1000000000);
}
}
else
{
alert("Please sync the device to see the data");
}
alert("steps: "+dis_steps+" times: "+dis_stime);
$scope.labels = dis_stime;
$scope.series = ['steps'];
$scope.data = dis_steps;
}
})
我從sqlite的插件獲取數據,然後我要顯示它的圖形。
問題是,調用select函數時圖不會加載。
在哪裏以及如何調用select函數以便在打開頁面時加載數據?
對我來說,你的代碼工作。您是否在項目中添加了cordova-sqlite-storage插件? – Vincismique