el-js中循环遍历el的集合

遇到问题的代码:

 var score=0;
            for(var i=0;i<${fn:length(tMovie.tComments) };i++){
                 score=${tMovie.tComments[i].userscore} ; 
}
问题:${tMovie.tComments[i].userscore} 取不到任何值
尝试:尝试把i变成0,取到了
总结:el表达式中不能取到js的变量
解决办法:
             var array = new Array();
             <c:forEach items="${tMovie.tComments }" var="tComment"> 
             array.push(${tComment.userscore }); //js中可以使用此标签,将EL表达式中的值push到数组中 
             </c:forEach>    
             for(var i=0;i<array.length;i++)    {
                 score=array[i];
。。。
}

局限性:只能取到el中的基本类型(字符串、数字等),不能取到对象

原文地址:https://www.cnblogs.com/yanyunliu/p/9717919.html