2016-05-24 15 views
0

gelöscht werden Ich habe ein Problem. Ich kann auch nicht die richtige Zeile aus einem Array mit angular.js löschen. Ich erkläre meinen Code unten.Die erforderliche Zeile kann nicht mit Angular.js/Javascript

<tr ng-repeat="d in days"> 
     <td>{{d.day_name}}</td> 
     <td> 
      <table> 
      <tbody> 
       <tr ng-repeat="answer in d.answers"> 
       <td> 
        <select class="form-control" id="answer_{{$index}}_{{$parent.$index}}_category" name="answer_{{$index}}_category" ng-model="answer.category" ng-options="cat.name for cat in listOfCategory track by cat.value" ng-change="removeBorder($index,answer.category.value,$parent.$index)" ng-init="renderWithMode($index,answer.category.value,$parent.$index,isEditMode)"> 
        <option value="">Select Category</option> 
        </select> 
       </td> 
       </tr> 
      </tbody> 
      </table> 
     </td> 
     <td> 
      <table> 
      <tbody> 
       <tr ng-repeat="answer in d.answers"> 
       <td> 
        <select class="form-control" id="answer_{{$index}}_{{$parent.$index}}_subcategory" name="answer_{{$index}}_subcategory" ng-model="answer.subcategory" ng-options="sub.name for sub in listOfSubCategory[$parent.$index][$index] track by sub.value"> 
        <option value="">Select Subcategory</option> 
        </select> 
       </td> 
       </tr> 
      </tbody> 
      </table> 
     </td> 
     <td> 
      <table> 
      <tbody> 
       <tr ng-repeat="answer in d.answers"> 
       <td> 
        <!--<input type="text" id="answer_{{$index}}_{{$parent.$index}}_comment" name="answer_{{$index}}_comment" placeholder="Add Comment" ng-model="answers.comment">--> 
        <input type="text" id="answer_{{$index}}_{{$parent.$index}}_comment" name="answer_{{$index}}_comment" placeholder="Add Comment" ng-model="answer.comment"> 
       </td> 
       </tr> 
      </tbody> 
      </table> 
     </td> 
     <td> 
      <table> 
      <tbody> 
       <tr ng-repeat="answer in d.answers"> 
       <td style="width:20px"> 
        <input ng-show="d.answers.length>1" class="btn btn-red" type="button" name="minus" id="minus" value="-" style="width:20px; text-align:center;" ng-click="removeRow(d.answers, $index)"> 
       </td> 
       <td ng-show="$last"> 
        <input type="button" class="btn btn-success" name="plus" id="plus" value="+" style="width:20px; text-align:center;" ng-click="addNewRow(d.answers)"> 
        <button type="button" id="btn" ng-click="checkAnswer(d.answers)">Check</button> 
       </td> 
       </tr> 
      </tbody> 
      </table> 
     </td> 
     </tr> 
    </tbody> 
      </table> 
     </td> 
     </tr> 

Die obige Tabelle gibt die Ausgabe wie folgt.

enter image description here

Hier habe ich 3 Zeile für Montag und nehme ich auf mittlere Reihe - Taste je nach Anforderung geklickt haben, das einzige mittlere Reihe löschen sollte, aber hier ist es löscht falsche Unterteil aus der 3. Reihe, dessen Bildschirm Schuss ist unten angegeben.

enter image description here

Ich habe zweite Reihe vom ersten Screenshot noch ist die zweite Reihe der Subkategorie Teil vorhanden und 3. Reihe Subkategorie Teil wird gelöscht, die falsche Lösch process.I unter sich erklärt, meinen Controller seitigen Code.

$scope.days=[]; 
    $http({ 
     method:'GET', 
     url:"php/customerInfo.php?action=day", 
     headers: { 'Content-Type': 'application/x-www-form-urlencoded' } 
    }).then(function successCallback(response){ 
     //console.log('day',response.data); 
    angular.forEach(response.data, function(obj) { 
     obj.answers = []; 
     $scope.addNewRow(obj.answers); 
     $scope.days.push(obj); 
    }); 
    },function errorCallback(response) { 
    }) 
    } 

    $scope.addNewRow = function(answers,hasDelete) { 
    answers.push({ 
     category: null, 
     subcategory: null, 
     comment: null, 
     hasDelete: hasDelete ? hasDelete : false 
    }); 
    }; 

    $scope.removeRow = function(answers, $index){ 
    answers.splice($index, 1); 
    //answers.splice(answers.length-1,1); 
    }; 

Hier sind alle Daten dynamisch gebunden. Ich muss die richtige Zeile löschen. Bitte helfen Sie mir.

Antwort

-1

Versuchen Sie, $ aus $ index Parameter zu entfernen.

$scope.removeRow = function(answers, index){ 
answers.splice(index, 1); 
//answers.splice(answers.length-1,1); 

};

+0

Ich tat wie Sie, aber es wirft das gleiche Problem. – satya

Verwandte Themen