根据存储的字段值删除多个键

Rud*_*osa 0 goinstant goangular

我有几个记录,其中有一个唯一的标识符,我希望在表单执行它的ajax帖子后删除它.假设我的goinstant存储中有5条记录,公共字段是xkey,其中的值包含123*.我的问题是如何干净地删除多个密钥?任何例子都会非常有帮助.

Slukeheart在最佳实践中得到了正确的答案:我找到了一个有效的解决方案,但我正在向Slukeheart提供正确的答案.这是我发现在今天发布解决方案的同时工作的内容:

$.ajax({
  url: './angtest',
  type: 'POST',
  contentType: 'application/json',
  data: JSON.stringify({ model: mymodelobj }),
  success: function (result) {
     //handleData(result);
     //remove old record entries to prevent table bloat.
  $scope.person = $goQuery('person', { xkey:  @Html.Raw(json.Encode(ViewBag.xkey1)) }, { limit: 30 }).$sync();
  $scope.person.$on('ready', function () {
    var tokill = $scope.person.$omit();
    angular.forEach(tokill, function(person,key) {
        $scope.person.$key(key).$remove();
    })
  });
  }
Run Code Online (Sandbox Code Playgroud)

});

Slu*_*art 6

GoAngular和Angular都使用promises,它提供了一种管理异步方法调用的有效方法(比如key.$remove).GoAngular使用Q promise库,Angular使用Q的子集,恰当地命名为$ q.

我刚刚简要总结了下面用共享xkey删除多个键,我还准备了一个更详细的工作plunkr.

angular
  .module('TestThings', ['goangular'])
  .config(function($goConnectionProvider) {
    $goConnectionProvider.$set('https://goinstant.net/mattcreager/DingDong');
  })
  .controller('TestCtrl', function($scope, $goKey) {
    var uid = 'xkey'; // This is created dynamically in the working example

    // Create a collection or promises, each will be resolved once the associated key has been removed.  
    var removePromises = ['red', 'blue', 'green', 'purple', 'yellow'].map(function(color) {
      return $goKey('colors/' + color + '/' + uid).$remove();
    });

    // Once all of the keys have been removed, we log out the destroyed keys
    Q.all(removePromises).then(function(removedColors) {
      removedColors.forEach(function(color) {
        console.log('Removed color with key', color.context.key);
      });
    }).fail(function() {
      console.log(arguments); // Called if a problem is encountered
    });
  });
Run Code Online (Sandbox Code Playgroud)