我使用angularJs和bootstrap。我已经制作了一个手风琴,我在其中选择了过滤器的值和数据-ng-模型不起作用(如果他不是手风琴,则选择有效)。这是我的代码:
<accordion close-others="oneAtATime">
<accordion-group is-open="isOpen">
<accordion-heading>
Country<i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': isOpen, 'glyphicon-chevron-right': !isOpen}"></i>
</accordion-heading>
<select data-ng-model="country" class="input-medium inputFilter form-control">
<option value="">All country</option>
<option value="1">Switzerland</option>
<option value="2">France</option>
<option value="3">Spain</option>
</select>
</accordion-group>
</accordion>
<div data-ng-repeat="city in listcity |filter:country">
{{city.name}}, {{city.country}}
</div>
我看过手风琴的UI-Bootstrap。我认为我必须做一个指令让它工作,但该指令不适用于手风琴。这是我的指令不起作用
app.directive('accordion', function () {
return {
scope: {
dataNgModel: '=',
},
};
});
答案 0 :(得分:6)
我不确定这是不是你想要的。但我使用ng-change来设置新的过滤器值。
控制器:
function AccordionDemoCtrl($scope) {
$scope.oneAtATime = true;
//default: all countrys
$scope.country = '';
//example data
$scope.listcity = [{
name: 'Madrid',
country: '3'
}, {
name: 'Paris',
country: '2'
}, {
name: 'Lyon',
country: '2'
}, {
name: 'Zurich',
country: '1'
}];
//set a new selection
$scope.setCountry = function(cid) {
$scope.country = cid;
}
}
标记:
<select ng-model="country" ng-change="setCountry(country)" class="input-medium inputFilter form-control">
看到它正常工作here
顺便说一句:示例指令是我见过的最短的指令。啊,我觉得这很简单: - )