Im は最近 angular-strap を実装し、Im はその複数選択を使用しています。正常に動作しますが、「すべて」というオプションが1つ必要であり、クリックすると、以前に選択した他のすべてのオプションが削除されます..
私が遊ぶ必要があるのは選択されたアイテムのリストだけなので、それを行う方法を理解することはできません..最後に選択されたものは1つもありません。どうすればこれを解決できますか? watch と 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');
};
}]);