基本上我有一组复选框,当它选中时会创建一组标签,但我创建了一个删除标签的功能,问题是,我无法弄清楚如何在删除标签时取消选中该复选框。 / p>
<div class="" ng-repeat="(key, value) in filterTags">{{value}}<div ng-click="changeTag(subproduct);">X</div></div>
<input type="checkbox" ng-model="active" ng-change="change(subproduct, active)">
以上是html以下的函数
$rootScope.change = function(subproduct, active){
if (active){
$rootScope.filterList.push(subproduct.subproduct_id);
$rootScope.filterPush = "?subproducts[]="+$rootScope.filterList.join("&subproducts[]=");
$rootScope.filterTags.push(subproduct.subproduct_name);
}
else{
$rootScope.filterList.splice($rootScope.filterList.indexOf(subproduct), 1);
$rootScope.filterPush = "?subproducts[]="+$rootScope.filterList.join("&subproducts[]=");
$rootScope.filterTags.splice($rootScope.filterTags.indexOf(subproduct), 1);
}
};
$rootScope.changeTag = function(subproduct, active){
$rootScope.filterList.splice($rootScope.filterList.indexOf(subproduct), 1);
$rootScope.filterPush = "?subproducts[]="+$rootScope.filterList.join("&subproducts[]=");
$rootScope.filterTags.splice($rootScope.filterTags.indexOf(subproduct), 1);
};
答案 0 :(得分:0)
试试这个
<input type="checkbox" ng-model="active" ng-change="change(subproduct, active)">
JS
$rootScope.filterTags = [];
$scope.change = function(subproduct, active){
var indexOf = $rootScope.filterTags.indexOf(subproduct.subproduct_name);
if(angular.equals(indexOf, -1)){
$rootScope.filterTags.push(subproduct.subproduct_name);
}
else{
$rootScope.filterTags.splice(indexOf, 1);
}
};