R
R
RodgerFox2015-07-08 02:44:36
JavaScript
RodgerFox, 2015-07-08 02:44:36

How to delete a variable in an array that is in an array?

I'm already banging my head against the wall. Constantly one error, the function is not defined.
Essence:
we have an array, in it under arrays, note:

$scope.gigliList = [{
            "gigli": [{
                "elemka": "kek"
            }, {
                "elemka": "kek"
            }]
        }, {
            "gigli": [{
                "elemka": "kek"
            }, {
                "elemka": "kek"
            }, {
                "elemka": "kek"
            }]
        }

And the structure of the shatamelochki:
<section ng-repeat="list in gigliList" ng-init="gigleIndex = $index">
   <div ng-repeat="item in list.gigli">...
         <factory> 
              <span ng-click="removeItem(gigleIndex, item, $index)">delete</span>
          </factory>
   </div>
</section>

repeat in repeat, calls the directive, there is a delete button in it, an element from the first array is not difficult:
$scope.removegigli = function(list) {
  var index = $scope.gigliList.indexOf(list); //выбираем нужный
        $scope.gigliList.slice(index, 1); // удаляем 
}

What about below array? Well, I tried everything I knew and re-read.
What now:
$scope.removeItem = function(gigleIndex, item, $index) {
// gigleIndex — номер массива родителя
// item сам элемент во втором репеате
// $index номер элемента в репеате. 
// и конечно же строчка ниже не работает 
$scope.gigleList[rowIndex].slice(item, 1);

$scope.gigleList[rowIndex] - why doesn't it work? I tried to put spice into myself, or I saw it somewhere or dreamed about it.
Can you please tell me how to properly "attach" to the sub array?
Add. posted on plnkr.co/edit/1G07tLDCZyjPHZOASuW5?p=preview (I took the variable names from the project's noun and they differ from the code above)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-07-08
@RodgerFox

let's quickly figure it out.
here we have a reference to an object, it does not have a splice method.
Next...
item is redundant here, since we're already passing in the element's index.
$scope.gridList[rowIndex].gigli.splice(index, 1)

E
Evgeny Kumanin, 2015-07-08
@jackkum

plnkr.co Post the code.
rowIndex - what is it and where does it come from?
splice() - the index is passed, and you shove the object there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question