Javascript 禁用NgRepeat中的NgOptions中的选项
我试图禁用每个“部分”(使用每个ng重复循环重置)中已选择的选项,但我无法找出如何最好地解决这种情况 我知道我应该使用“disabled when”,但无法确定如何创建该(数组?)或在已选择每个选择选项时跟踪(并对该ngRepeat循环中的另一个选择将其禁用)。我需要允许在“section”部分中选择相同的选择选项 非常感谢您的建议,谢谢! 我通过例子学习得最好,希望这对其他学习AngularJS的人有益 如图所示: 我有以下AngularJs标记Javascript 禁用NgRepeat中的NgOptions中的选项,javascript,angularjs,Javascript,Angularjs,我试图禁用每个“部分”(使用每个ng重复循环重置)中已选择的选项,但我无法找出如何最好地解决这种情况 我知道我应该使用“disabled when”,但无法确定如何创建该(数组?)或在已选择每个选择选项时跟踪(并对该ngRepeat循环中的另一个选择将其禁用)。我需要允许在“section”部分中选择相同的选择选项 非常感谢您的建议,谢谢! 我通过例子学习得最好,希望这对其他学习AngularJS的人有益 如图所示: 我有以下AngularJs标记 <body ng-app="app"&g
<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>
部分
项目名称
您可以对
ng选项,使用禁用语法disable when condition
(通过关键字快速搜索:disable when
)
UPD:
根据您的情况,您可以使用sectionid
(通过sectionid轻松设置和获取)键维护一个对象
,并为每个元素动态生成禁用条件
// 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
为当前节生成条件数据
Plunker.谢谢,但我如何跨节动态执行此操作?@spookybot您可以根据您的节更改禁用条件。@spookybot再次查看示例,我已将特殊条件添加到您的类型
数组中。该示例未按预期工作。当我选择一个选项时,应在相邻的sele中禁用该选项ctI也无法根据业务模式修改现有阵列。感谢您的帮助
// 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)
...
],
...
}