Javascript DB查询与更新AngularJS中的$scope变量&;索引数据库
我在AngularJS&IndexedDB上运行的离线应用程序中有一个三步流程 在页面加载时,我进行DB调用,以列出具有今天日期的所有记录(进入Javascript DB查询与更新AngularJS中的$scope变量&;索引数据库,javascript,angularjs,indexeddb,Javascript,Angularjs,Indexeddb,我在AngularJS&IndexedDB上运行的离线应用程序中有一个三步流程 在页面加载时,我进行DB调用,以列出具有今天日期的所有记录(进入recordlist变量): 然后我可以添加新记录,但为了更新记录列表,我正在做另一个调用: $scope.addRecord = function (records) { $indexedDB.openStore('records', function(store){ $scope.newrecord = { "date": $
recordlist
变量):
然后我可以添加新记录,但为了更新记录列表
,我正在做另一个调用:
$scope.addRecord = function (records) {
$indexedDB.openStore('records', function(store){
$scope.newrecord = {
"date": $scope.dateJson,
"time": $scope.time,
"arrival": '',
"inserted": ''
}
store.insert($scope.newrecord).then(function(e){});
var find = store.query();
find = find.$eq($scope.dateJson);
find = find.$index("date_idx");
store.eachWhere(find).then(function(e){
$scope.recordlist = e;
});
});
};
$scope.insertRecord = function (record) {
$indexedDB.openStore('records', function(store){
store.upsert(
{
"ssn": record.ssn,
"date": record.date,
"time": record.time,
"arrival": moment().format("HH.mm.ss"),
"inserted": true,
}).then(function (e) {
var find = store.query();
find = find.$eq($scope.dateJson);
find = find.$index("date_idx");
store.eachWhere(find).then(function(e){
$scope.recordlist = e;
});
});
});
};
最后,我用到达时间更新记录,执行另一个DB调用:
$scope.addRecord = function (records) {
$indexedDB.openStore('records', function(store){
$scope.newrecord = {
"date": $scope.dateJson,
"time": $scope.time,
"arrival": '',
"inserted": ''
}
store.insert($scope.newrecord).then(function(e){});
var find = store.query();
find = find.$eq($scope.dateJson);
find = find.$index("date_idx");
store.eachWhere(find).then(function(e){
$scope.recordlist = e;
});
});
};
$scope.insertRecord = function (record) {
$indexedDB.openStore('records', function(store){
store.upsert(
{
"ssn": record.ssn,
"date": record.date,
"time": record.time,
"arrival": moment().format("HH.mm.ss"),
"inserted": true,
}).then(function (e) {
var find = store.query();
find = find.$eq($scope.dateJson);
find = find.$index("date_idx");
store.eachWhere(find).then(function(e){
$scope.recordlist = e;
});
});
});
};
我的问题是,考虑到我在第一次调用时已经在检索recordlist
,不需要在每个步骤(添加/插入)上进行服务器查询就可以动态更新它,这不是更简单吗
最后,数据还是会被保存的,当我可能只是将新数据附加到记录列表
中时,是否需要一次又一次地检索它,以及由此带来的性能问题
如果是这样,我该怎么做
我是数据库新手,在最佳实践和工作流程方面我有点迷茫