Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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 使用angular操作异步调用_Javascript_Angularjs_Mongodb - Fatal编程技术网

Javascript 使用angular操作异步调用

Javascript 使用angular操作异步调用,javascript,angularjs,mongodb,Javascript,Angularjs,Mongodb,我有一个显示MongoDB事件的日历。 每次用户单击prev或next按钮时,我都会执行一个异步调用,然后重置日期和事件的当前数组;但是,如果用户多次单击某个按钮,将显示双重结果 $scope.next = function () { //reset array $scope.gridOptions.data=[]; //date of week myService.dbAction(dt3,dt4).then(function (data) {

我有一个显示MongoDB事件的日历。 每次用户单击prev或next按钮时,我都会执行一个异步调用,然后重置日期和事件的当前数组;但是,如果用户多次单击某个按钮,将显示双重结果

 $scope.next = function () {
     //reset array
    $scope.gridOptions.data=[];

    //date of week

    myService.dbAction(dt3,dt4).then(function (data) {

      check(data);
      $scope.gridOptions.data = $scope.setts;//update data
    }, function (error) {
      console.error('ERROR: ' + error);
    })
 }

我只想要上周的事件,怎么做?

一个快速解决方法是添加一个
fetchPending
标志。使用它可以避免重复获取

$scope.next = function () {
    if ($scope.fetchPending) return;
    $scope.fetchPending = true;
    //reset array
    $scope.gridOptions.data=[];

    //date of week

    myService.dbAction(dt3,dt4).then(function (data) {

      check(data);
      $scope.gridOptions.data = $scope.setts;//update data

    }).catch ( function (error) {
       console.error('ERROR: ' + error);
    }).finally( function () {
       $scope.fetchPending = false;
    })
 }

视情况而定。是否要阻止用户单击上一步/下一步,直到返回结果?或者你想让他们尽可能快地点击按钮,但只保留最新信息吗?我想显示最新信息