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中的基本類型(字符串、數字等),不能取到對象


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM