gpt4 book ai didi

javascript - 根据数组中值的 ngChange 更新禁用 ngOptions

转载 作者:行者123 更新时间:2023-11-28 04:37:49 25 4
gpt4 key购买 nike

我正在尝试在选择选项后禁用它们。这取决于与每个“cusomter_no”关联的“perf_no”,如以下代码所示。 ngChange 在更新模型的同时更新关联对象中的“disabled”值。 debounce 的 ngModelOptions 对我不起作用。 有没有办法在 ngChange 完成后进行回调以更新该对象的“禁用”值?或者也许有更好的方法来实现这一目标?提前致谢。

<div class="session-registrant-field field-dropdown">
<label for="">{{nameLbl}}</label>
<select
ng-model="affiliateSelected[cartPerf.perf_no][$index]"
ng-change="changedAffiliate(affiliateSelected, cartPerf.perf_no, $index, affiliateSelected[cartPerf.perf_no][$index].customer_no)"
ng-options="affiliate.fname + ' ' + affiliate.lname disable when affiliate.disabled for affiliate in affiliates | filter:cartPerf.perf_no | orderBy:affiliate.customer_no:true track by affiliate.customer_no"
required>
<option value="" disabled="">-- Select person --</option>
</select>
</div>

Controller 片段

$scope.affiliates = [
{"id":"1","perf_no":"154","perf_dt":"2017-09-18T10:00:00","customer_no":"-10003","fname":"","lname":"Add New Child","validation_pass_age":"Y","validation_pass_prereq":"Y","ask_birthdate":"Y","ask_current_grade":"Y","ask_next_grade":"Y","ask_email":"N","bdatereq":"Y","age_validation_ind":"Y","min_age":"10","max_age":"25","rel_type_id":"10003"},
{"id":"2","perf_no":"154","perf_dt":"2017-09-18T10:00:00","customer_no":"-10002","fname":"","lname":"Add New Adult","validation_pass_age":"Y","validation_pass_prereq":"Y","ask_birthdate":"Y","ask_current_grade":"Y","ask_next_grade":"Y","ask_email":"N","bdatereq":"Y","age_validation_ind":"Y","min_age":"10","max_age":"25","rel_type_id":"10002"},
{"id":"3","perf_no":"154","perf_dt":"2017-09-18T10:00:00","customer_no":"2762","fname":"Ryan","lname":"Jones","age":"22","validation_pass_age":"Y","validation_pass_prereq":"Y","ask_birthdate":"Y","ask_current_grade":"N","ask_next_grade":"N","ask_email":"Y","birthdate":"07\/13\/1995","bdatereq":"Y","eaddress":"","age_validation_ind":"Y","min_age":"10","max_age":"25","rel_type_id":"10003"},
{"id":"4","perf_no":"154","perf_dt":"2017-09-18T10:00:00","customer_no":"2700","fname":"John","lname":"Doe","age":"","validation_pass_age":"Y","validation_pass_prereq":"Y","ask_birthdate":"Y","ask_current_grade":"N","ask_next_grade":"N","ask_email":"Y","birthdate":"02\/22\/1988","bdatereq":"Y","eaddress":"","age_validation_ind":"Y","min_age":"10","max_age":"25","rel_type_id":"10003"},
{"id":"5","perf_no":"154","perf_dt":"2017-09-18T10:00:00","customer_no":"2701","fname":"Rick","lname":"Deckard","age":"","validation_pass_age":"Y","validation_pass_prereq":"Y","ask_birthdate":"Y","ask_current_grade":"N","ask_next_grade":"N","ask_email":"Y","birthdate":"02\/22\/1988","bdatereq":"Y","eaddress":"","age_validation_ind":"Y","min_age":"10","max_age":"25","rel_type_id":"10002"},
{"id":"1","perf_no":"93","perf_dt":"2017-09-18T10:00:00","customer_no":"-10003","fname":"","lname":"Add New Child","validation_pass_age":"Y","validation_pass_prereq":"Y","ask_birthdate":"Y","ask_current_grade":"Y","ask_next_grade":"Y","ask_email":"N","bdatereq":"Y","age_validation_ind":"Y","min_age":"10","max_age":"25","rel_type_id":"10003"},
{"id":"2","perf_no":"93","perf_dt":"2017-09-18T10:00:00","customer_no":"-10002","fname":"","lname":"Add New Adult","validation_pass_age":"Y","validation_pass_prereq":"Y","ask_birthdate":"Y","ask_current_grade":"Y","ask_next_grade":"Y","ask_email":"N","bdatereq":"Y","age_validation_ind":"Y","min_age":"10","max_age":"25","rel_type_id":"10002"},
{"id":"3","perf_no":"93","perf_dt":"2017-09-18T10:00:00","customer_no":"2762","fname":"Ryan","lname":"Jones","age":"22","validation_pass_age":"Y","validation_pass_prereq":"Y","ask_birthdate":"Y","ask_current_grade":"N","ask_next_grade":"N","ask_email":"Y","birthdate":"07\/13\/1995","bdatereq":"Y","eaddress":"","age_validation_ind":"Y","min_age":"10","max_age":"25","rel_type_id":"10003"},
{"id":"4","perf_no":"93","perf_dt":"2017-09-18T10:00:00","customer_no":"2700","fname":"John","lname":"Doe","age":"","validation_pass_age":"Y","validation_pass_prereq":"Y","ask_birthdate":"Y","ask_current_grade":"N","ask_next_grade":"N","ask_email":"Y","birthdate":"02\/22\/1988","bdatereq":"Y","eaddress":"","age_validation_ind":"Y","min_age":"10","max_age":"25","rel_type_id":"10003"}
]

$scope.changedAffiliate = function(selectedItem, cartPerfNo, index, affiliateCustomer_no) {
$.each($scope.affiliates, function(i) {
if(this.perf_no === cartPerfNo && this.customer_no === affiliateCustomer_no){
this['disabled'] = true;
}
});
}
$scope.getDisableCondition = function(affiliate, cartPerfNo, index){
$.each($scope.affiliates, function(i) {
if(this.disabled === true){
console.log(this);
return affiliate.customer_no === this.customer_no;
}
if(this.disabled === false || this.disabled === undefined){
return false;
}
//console.log(this);

});
}
<小时/>

Full Plunker here

最佳答案

嗯,也许它不漂亮,但完成了它的工作( plnkr ):

    $scope.passMe;

$scope.changedAffiliate = function(selectedItem, cartPerfNo, index, affiliateCustomer_no) {
if ($scope.passMe) {
$scope.affiliates.forEach((aff)=>{
if (aff.perf_no == $scope.passMe[0] && aff.customer_no == $scope.passMe[2]) {
selectedItem[$scope.passMe[0]][ $scope.passMe[1]] = aff
}
})
$scope.passMe = null;
}
$scope.passMe = [cartPerfNo,index,affiliateCustomer_no]
$.each($scope.affiliates, function(i) {
if(this.perf_no === cartPerfNo && this.customer_no === affiliateCustomer_no){
this['disabled'] = true;
}
});

}

这是基于以下事实:changedAffiliate 在被禁用后将额外运行 1 次。

关于javascript - 根据数组中值的 ngChange 更新禁用 ngOptions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44038257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com