Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 想要获取标签,但视图中未显示任何内容 函数被AngularJS中的表达式过度调用_Javascript_Angularjs_Angularjs Select - Fatal编程技术网

Javascript 想要获取标签,但视图中未显示任何内容 函数被AngularJS中的表达式过度调用

Javascript 想要获取标签,但视图中未显示任何内容 函数被AngularJS中的表达式过度调用,javascript,angularjs,angularjs-select,Javascript,Angularjs,Angularjs Select,我想将标签绑定到选项标记中的selectedType值,但视图中没有显示任何内容,控制台中有许多调用 view.jsp {{exprModelTypeRCDModel.selectedType} Controller.js $scope.exprModelType = function(typeModel) { if (typeModel != undefined) { $scope.reunionType.forEach(function (type) {

我想将标签绑定到选项标记中的selectedType值,但视图中没有显示任何内容,控制台中有许多调用

view.jsp

{{exprModelTypeRCDModel.selectedType} 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 "";
}

forEach块内的return语句不向父函数返回值

而是使用:

有关详细信息,请参阅


是要显示reunionType数组中的选定模型,还是要显示reunionType数组中存在的所有值?仅显示选定模型。reunionType数组是id/label的键/值,我的模型只包含id。因此,我必须将标签链接到id模型。我使用AngularJS 1.3IE不支持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 "";
}