我最近使用了多个选择实现了角带和Im。 它工作正常,但现在我想有一个选项说“全部”,如果点击它将删除所有其他以前选择的选项..
无法弄清楚如何操作,因为我必须使用的是所选项目的列表..没有单一的最后选择哪个有用。我怎么能解决这个问题? 尝试玩手表和onChange。
看起来像这样:
HTML
<button type="button" class="btn btn-default" placeholder="Filtrera på kategori" ng-model="selectedCategories" data-html="1" data-multiple="1" max-length="6" data-animation="am-flip-x" ng-options="category.Id as category.Name for category in categories" bs-select>
Action <span class="caret"></span>
</button>
JS控制器
orderContrl.controller('addProductInternalController', ['$scope', '$modalInstance', 'productItemCategories',
function ($scope, $modalInstance, productItemCategories) {
init();
$scope.selectedCategories = [productItemCategories[0].Id];
$scope.categories = productItemCategories;
function init() {
};
$scope.$watch("selectedCategories", function (newValue, oldValue) {
console.log(newValue);
console.log(oldValue);
});
$scope.changeSelectedCategories = function (selectedCategories) {
if (selectedCategories.length > 1 && selectedCategories[0] == -1)
selectedCategories.shift();
//else {
// angular.forEach(selectedCategories, function (item) {
// if (item == -1)
// saveProductToOrder(item);
// });
//}
if (selectedCategories.length > 1 && selectedCategories[0] == -1)
selectedCategories.shift();
console.log(selectedCategories);
};
// Closes modal and sets chosen treeview value
$scope.ok = function () {
};
// Closes modal and cancels
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}]);