【发布时间】: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