gpt4 book ai didi

javascript - 想要获取标签但 View 中没有显示任何内容

转载 作者:行者123 更新时间:2023-12-02 21:28:44 25 4
gpt4 key购买 nike

AngularJS 中的函数被表达式调用

我想要将标签绑定(bind)到选项标记中的 selectedType 值,但 View 中没有显示任何内容,并且控制台中有很多调用

View .jsp

<select ng-if="RCDModel.id!=-1" class="form-control overloadDC"
title="blablabla" disabled>
<option value="{{RCDModel.selectedType}}">
{{exprModelType(RCDModel.selectedType)}}
</option>
</select>

Controller .js

$scope.exprModelType = function(typeModel) {
if (typeModel != undefined) {
$scope.reunionType.forEach(function (type) {
console.log("TYPE: "+type);
if (type.id == typeModel) {
console.log("TYPE ID: "+type.id);
console.log("TYPE ID: "+typeModel);
console.log("Libele: "+type.libelle);
return type.libelle;
}
});
}
return "";
}

enter image description here

最佳答案

forEach block 内的 return 语句不会向父函数返回值。

而是使用 array.find :

$scope.exprModelType = function(typeModel) {
if (typeModel != undefined) {
var idMatch = $scope.reunionType.find( _ => _.id == typeModel.id );
console.log("TYPE: "+idMatch);
console.log("TYPE ID: "+idMatch.id);
console.log("TYPE ID: "+idModel);
console.log("Libele: "+idMatch.libelle);
return idMatch ? idMatch.libelle : "";
}
return "";
}

欲了解更多信息,请参阅

关于javascript - 想要获取标签但 View 中没有显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60675041/

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