2016-10-06 101 views
0

我试图删除级联下拉列表复选框,即下拉列表中的项目及其相关的复选框项目必须在按钮被删除时点击。我无法从下拉列表中删除选定的项目,所以请帮我删除所需的项目。删除级联下拉列表中的项目

link

HTML:

<ion-view view-title="Car Type"> 
    <ion-content ng-contorller="carBrand"> 
    <h3> Add/Edit the Car Types </h3> 
    {{sample}} 
    Make: 
     <!--select name="client" ng-model="selectedRequest.continent" ng-options="c.name for c in brandList" required></select--> 
     <select ng-model="carBrand" ng-options="make.name for make in brandList"></select> 
    Type: 
    <ion-checkbox ng-model="cartype" ng-repeat="brandType in carBrand.types" ng-disabled="!carBrand"> 
    <span>{{brandType}}</span> 
    </ion-checkbox><br><br> 
    <button ng-click="addEntry()">Edit</button> 
    <button ng-click="home()">Back</button> 
    <button ng-click="delete($index)">Delete</button> 
    </ion-content> 
</ion-view> 

控制器:

var carService =angular.module('carService', ['ionic']); 
carService.controller('carBrand',['$scope',function($scope){ 

$scope.brandList=[ 
{'name':'Benz', 'types':['SUV', 'Sedan']}, 
{'name':'BMW', 'types':['SUV', 'Sedan', 'Van']} 
]; 

$scope.remove=function(index){ 
    delete $scope.brandList[$index]; 
}; 
}]); 

回答

0

remove是不正确的

$scope.remove = function(){ 
    $scope.brandList.splice($scope.brandList.indexOf($scope.carBrand), 1); 
    $scope.carBrand = {}; 
}; 

你也没有在HTML和控制器delete != remove

<button ng-click="remove()">Delete</button> 

,正确ng-contorller相同名称ng-controller

Splice允许您通过删除现有元素和/或增加新的元素来改变数组的内容。

+0

这将有助于删除{name:Benz,types:['suv','seadan']},并且可以将它放在plnkr中,以便理解它。 – sree

+0

删除下拉列表中的项目并没有发生列表@taguenizy – sree

+0

[plnkr](https://plnkr.co/edit/SdRRcw57vmYJMsJLo7l1?p=preview)@sree – taguenizy