【问题标题】:Ng-click works on double tap onlyNg-click 仅适用于双击
【发布时间】:2017-03-23 19:09:53
【问题描述】:

当我在这个离子删除图标上按两次时,它只会删除项目。所以请纠正我。提前致谢。

这是我的 div 调用函数“removeFromWishList(obj,$index)”

       <div class="col" ng-click="removeFromWishList(obj,$index)" > 
          <i class="icon ion-ios-trash-outline font_20px"  ></i>
        </div>

这是我在控制器中的 removeFromWishList(obj,$index) 函数

$scope.removeFromWishList = function (obj, index) {
  if ($scope.wishlistItems.indexOf(obj.id) > -1) {
    angular.forEach($scope.wishlistItems, function (val, key) {
      if (val == obj.id) {
        $scope.wishlistItems.splice(key, 1);
        Wishservice.remwishid(index);


      }
      $state.go($state.current, {}, {reload: true});
    });
  } else {
    $scope.wishlistItems.push(obj.id);
  }
};

【问题讨论】:

  • 函数 removeFromWishList 被调用了两次?
  • 是的,实际上该功能将删除 1 个项目,但实际上它发生在我按两次时。
  • $scope.wishlistItems.splice($scope.wishlistItems.indexOf(obj.id),1) 你可以试试这个从列表中删除项目吗? (假设 wishItems 是 id 列表,而不是对象)
  • 非常感谢您的建议。不幸的是,它会抛出这样的错误“无效或意外令牌”。我可以通过编写一个调用该函数两次的新函数来解决该错误,然后在删除按钮按下时调用新函数。

标签: html angularjs ionic-framework


【解决方案1】:

请试试这个代码:

$scope.removeFromWishList = function(obj, index) {
    var index = $scope.wishlistItems.indexOf(obj.id);
    if (index > -1) {
        $scope.wishlistItems.splice(index, 1);
        $state.go($state.current, {}, {reload: true}); // not sure why this is needed
    } else {
        $scope.wishlistItems.push(obj.id);
    }
};

【讨论】:

  • 感谢您为此付出的努力。但是这段代码不起作用(没有错误)
  • 好像跟刷新内容什么的有关。你有什么建议吗?
  • 你能提供 Plunker 链接吗?还可以尝试在函数中注释 $state.go 行。
猜你喜欢
  • 1970-01-01
  • 2015-01-18
  • 2014-07-16
  • 1970-01-01
  • 1970-01-01
  • 2016-04-16
  • 2019-07-01
  • 2019-04-19
  • 1970-01-01
相关资源
最近更新 更多