我正在使用AngularJS過濾器,它的工作良好。見我的代碼:使用AngularJS過濾器更改類別或不透明度
(function() {'use strict';
angular.
module('myApp', []).
controller('WineCtrl', WineCtrl);
// Functions - Definitions
function WineCtrl() {
// Variables - Private
var self = this;
// Variables - Public
self.filter = {};
self.wines = [
{name: 'Wine A', category: 'red'},
{name: 'Wine B', category: 'red'},
{name: 'Wine C', category: 'white'},
{name: 'Wine D', category: 'red'},
{name: 'Wine E', category: 'red'},
{name: 'Wine F', category: 'white'},
{name: 'Wine G', category: 'champagne'},
{name: 'Wine H', category: 'champagne'}
];
// Functions - Public
self.filterByCategory = filterByCategory;
self.getCategories = getCategories;
// Functions - Definitions
function filterByCategory(wine) {
return self.filter[wine.category] || noFilter(self.filter);
}
function getCategories() {
return (self.wines || []).
map(function (wine) { return wine.category; }).
filter(function (wine, idx, arr) { return arr.indexOf(wine) === idx; });
}
function noFilter(filterObj) {
return Object.
keys(filterObj).
every(function (key) { return !filterObj[key]; });
}
}
}());
但我不想讓他人隱瞞,當我選擇一個項目。相反,我想改變別人的風格(不透明或其他)。 我需要做什麼?
可以使用納克級添加CSS效果,其他沒被選 – Niladri
@Niladri這不是一個答案。你能給我更多的細節嗎?謝謝。 – Jelaloy
你可以在重複的div上使用ng-class來設置滿足如下條件的css類:'ng-class =「{checked:wine.category!='你選擇的複選框的ng-model值'} – Niladri