我试图禁用每个“部分”中的已选择选项(每个ng-repeat循环重置),但是我无法弄清楚如何最好地解决这种情况。
我知道我应该使用“何时禁用”,但无法弄清楚如何创建(数组?)或跟踪何时已选择每个选择选项(并使该ngRepeat循环中的其他选择禁用)。我需要允许能够在“部分”中选择相同的选择选项。
任何建议深表感谢。提前致谢!
我以身作则,学得最好,希望对其他学习AngularJS的人有益。
如下面的代码所示:Plunker
我有以下AngularJs标记
<body ng-app="app">
<div ng-controller="main">
<hr>
<div ng-repeat="section in sections track by section.sectionid" ng-model="section.sectionid">
<p>Section</p>
<div ng-model="typeModel" ng-repeat="type in types | filter:section.sectionid">
<p>item name</p>
<select ng-model="itemSelected" ng-options="item.name for item in items track by item.id">
</select>
</div>
<hr>
</div>
</div>
最佳答案
您可以对disable when condition
,documentation here使用禁用语法ng-options
(通过关键字快速搜索:disable when
)。
ng-options="item.name disable when item.name==='2' for item in items track by item.itemid"
UPD:
根据您的情况,您可以使用
object
键维护一个sectionid
(易于通过sectionid进行设置),并且对于每个部分,可以为每个select
元素动态生成禁用条件。// object looks like this
$scope.sectionSelectedItem = {
1: [
concition1, // for first select of sectionid(1)
concition2, // for second select of sectionid(1)
...
],
2: [
concition1, // for first select of sectionid(2)
concition2, // for second select of sectionid(2)
...
],
...
}
每次更改节的
select
元素时,都可以通过ng-change
为当前节生成条件数据。柱塞demo。