如何在 jQuery 中对数组使用 $.each 方法?
function calcTotalScore(){
var arr = ["A","B","C","D","E","F"];
$.each(arr, function(n,val){
calcTotal(val);
});
}
calcTotal(value){
// sample code
}
我在 Velocity 模板语言(VTL)中使用上述函数 calcTotalScore() ,但它说:
Encountered "," Was expecting one of:
<EOF>
"(" ...
<RPAREN> ...
<ESCAPE_DIRECTIVE> ...
<SET_DIRECTIVE> ...
"##" ...
"\\\\" ...
"\\" ...
<TEXT> ...
"*#" ...
"*#" ...
<STRING_LITERAL> ...
<IF_DIRECTIVE> ...
<STOP_DIRECTIVE> ...
<INTEGER_LITERAL> ...
<FLOATING_POINT_LITERAL> ...
<WORD> ...
<BRACKETED_WORD> ...
<IDENTIFIER> ...
<DOT> ...
"{" ...
"}" ...
我做错了什么?
function calcTotalScore(){
var arr = ["A","B","C","D","E","F"];
$.each(arr, function(n,val){
calcTotal(val);
});
}
calcTotal(value){
// sample code
}
I am using the above function calcTotalScore()
in Velocity Template Language(VTL), but it says:
Encountered "," Was expecting one of:
<EOF>
"(" ...
<RPAREN> ...
<ESCAPE_DIRECTIVE> ...
<SET_DIRECTIVE> ...
"##" ...
"\\\\" ...
"\\" ...
<TEXT> ...
"*#" ...
"*#" ...
<STRING_LITERAL> ...
<IF_DIRECTIVE> ...
<STOP_DIRECTIVE> ...
<INTEGER_LITERAL> ...
<FLOATING_POINT_LITERAL> ...
<WORD> ...
<BRACKETED_WORD> ...
<IDENTIFIER> ...
<DOT> ...
"{" ...
"}" ...
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
VTL 将 jQuery 的
$
解释为变量的开头。然后它会抱怨,因为变量名不能以点开头。您有两个选择:
\$
jQuery
而不是$
VTL is interpreting jQuery's
$
as the start of a variable. It then complains because a variable name cannot start with a dot.You have two options:
\$
jQuery
instead of$
更新
查看a'r的答案:D
你只是在calcTotal前面缺少一个“函数”;)
http://fiddle.jshell.net/gabel/7SvUY/1/
UPDATE
see answer of a'r :D
You're just missing a "function" in front of calcTotal ;)
http://fiddle.jshell.net/gabel/7SvUY/1/