Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript DB查询与更新AngularJS中的$scope变量&;索引数据库_Javascript_Angularjs_Indexeddb - Fatal编程技术网

Javascript DB查询与更新AngularJS中的$scope变量&;索引数据库

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": $

我在AngularJS&IndexedDB上运行的离线应用程序中有一个三步流程

在页面加载时,我进行DB调用,以列出具有今天日期的所有记录(进入
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
,不需要在每个步骤(添加/插入)上进行服务器查询就可以动态更新它,这不是更简单吗

最后,数据还是会被保存的,当我可能只是将新数据附加到
记录列表
中时,是否需要一次又一次地检索它,以及由此带来的性能问题

如果是这样,我该怎么做

我是数据库新手,在最佳实践和工作流程方面我有点迷茫