gpt4 book ai didi

javascript - 禁用具有特定标签的多重选择的optgroup

转载 作者:行者123 更新时间:2023-11-30 17:05:48 24 4
gpt4 key购买 nike

我使用 ng-options 选择了一个包含多个选项的选择列表。我正在使用它如下:

<select ng-options="c as c.Text for c in ReceiverList track by c.Value" ng-model="ReceiverUserID" class="form-control" id="ddlReceiverUserID" ng-change="GetWorkers(ReceiverUserID, SenderUserID,'receiver')">
<option value="">--Select Supervisor--</option>
</select> <!-- Parent Drop Down-->

<select multiple ng-options="c as c.Text group by c.Group
for c in receiveList track by c.Value" ng-model="Workers"
class="form-control" id="ddlWorkers" size="10">
</select> <!-- Child Drop Down -->

当我从另一个下拉列表中选择某些项目时,此选择下拉列表会被填充。(这是一种级联下拉列表)。填写如下:

$scope.GetWorkers = function (objA, objB, ddlType) {
$http.post("user/Workers/", { userID: objA.Value })
.success(function (data, status, headers, config) {
if (ddlType == 'sender') {
$scope.sendList = data;
} else {
$scope.receiveList = data;
$('#ddlWorkers optgroup[label="Current Users"] option').prop('disabled', true); // Not working
}
})
.error(function (data, status, headers, config) {
showToast(ToastType.error, "Error occured while fetching workers.", "Failure");
});
}

我想禁用子下拉列表的特定组项目。所以我尝试了下面的代码,但它不起作用:

$('#ddlWorkers optgroup[label="Current Users"] option').prop('disabled', true);

我不知道如何在数据更改或加载新数据时禁用 select 的特定组项目。

这是我想禁用所有 optgroup[label="Current Users"] 成员的 HTML 输出:

<select multiple="" ng-options="c as c.Text group by c.Group for c in receiveList track by c.Value" ng-model="Workers" class="form-control ng-pristine ng-valid" id="ddlWorkers" size="10">
<optgroup label="Current Users">
<option value="4118">Kevins Numen</option>
<option value="4119">ggdfg fdgdfg</option>
</optgroup>
<optgroup label="New Users">
<option value="1093">Case Worker</option>
</optgroup>
</select>

最佳答案

我不太了解 angularjs 或 ng-options,但似乎其他人都使用了一些超时让进程将接收到的数据填充到输入中,您可以像其他人一样尝试这样做:

... 
} else {
$scope.receiveList = data;
setTimeout(function(){
$('#ddlWorkers optgroup[label="Current Users"] option')
.prop('disabled', true); // Not working
}, 100);
}
...

可能不相似但很高兴在这里看看:

is there a post render callback for Angular JS directive?

关于javascript - 禁用具有特定标签的多重选择的optgroup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28064651/

24 4 0