에서 개체를 제거내가 다음 코드 한 배열
app.controller('modalController', function($scope, $http,$modalInstance, $rootScope, items){
// Get info
$http.post('/ajax/bundle', {'items':items}).success(function(data){
$scope.info = data['info'];
});
// [BUTTON] Add Bundle
$scope.selectBundle = function() {
// Push the info to the cart
$rootScope.cart.push($scope.info);
// simplified info
$rootScope.selectedBundle.push(items)
// Close modal
$modalInstance.close();
}
// [BUTTON] Remove bundle
$scope.removeBundle = function() {
// Run all bundles
angular.forEach($rootScope.selectedBundle,function(value, key){
// Exists
if (angular.equals(value,items)) {
// Remove simplified
$rootScope.selectedBundle.splice($rootScope.selectedBundle.indexOf(value), 1);
// remove form cart
// $rootScope.cart.splice($rootScope.cart.indexOf($scope.info), 1);
}
});
// Close modal
$modalInstance.close();
}
});
내가 사용하는 경우 : 내가 $에서 사용할 때
$ scope.selectBundle에서console.log($rootScope.cart);
console.log($scope.dados);
console.log($rootScope.cart.indexOf($scope.dados));
, 지금 정확한 위치
을 반환 scope.removeBundle, 항상 -1을 반환합니다 (찾을 수 없음)
누군가가 도와 줄 수 있습니까?
는 경우 항목의 값 (angular.equals (값, 항목)) 어떤 경우? – SoluableNonagon
items = [묶음, 두께, 등급, 대구, nbloco]; – PGz