我有一个更改密码页面,我输入当前密码,更改密码,这将发送到后端,在后端我正在做一些过程,如果密码相关标准没有'匹配。在下面的代码中,我将所有3个错误存储在 changePasswordError 对象中,借助于速度foreach循环,我将其存储到名为e的循环变量中。
这是速度的foreach循环,这里是changePasswordError im存储所有错误并存储到loop变量e。
#foreach( $e in $errors.get("changePasswordError") )
<div class="ui-state-error" >$e</div>
<br/>
#end
我想显示这个loopvariable e进入javascript。我怎么能实现这个?
<script>
$(document).ready(function(){
$("#loginDlg1").before('
<div class="ui-state-error" >
//wanted to show the error message e here...how i can display here
</div>
');
});
</script>
任何帮助将不胜感激。谢谢
答案 0 :(得分:0)
好的,最后我可以在速度模板的set指令的帮助下将循环变量转换为javascript。
以下是解决方案
#foreach( $e in $errors.get("changePasswordError") )
#set ($editAttr=$e) // here im setting the loopvariable e into temp variable editAttr
#end
<script>
$(document).ready(function(){
var v = "$editAttr"; // by this i am able to retrieve in javascript.
alert("$editAttr"); // or if i want to alert directly the velocity elements into javascript then can able to alert like this
$("#loginDlg1").before('<div class="ui-state-error">$editAttr</div>');
});
</script>