[英]Array.each outputs all methods
Why would... 为什么会...
for(var k in this.errors) {
$('error_list').insert({
bottom: new Element('li').update(k + ' :'+this.errors[k])
})
}
...output put all Prototype enumerable methods, plus what I've added to the array? ...输出放置了所有Prototype可枚举的方法,以及我添加到数组中的内容?
I'm building an associative array: 我正在建立一个关联数组:
this.errors['email'] = 'Your email is invalid';
您需要使用“ hasOwnProperty”来防止这种情况。
You may prevent this using hasOwnProperty : 您可以使用hasOwnProperty来防止这种情况:
for(var k in this.errors) {
if (this.errors.hasOwnProperty(k)) {
$('error_list').insert({
bottom: new Element('li').update(k + ' :'+this.errors[k])
})
}
}
Try this: 尝试这个:
$H(this.errors).each(function(error) {
$('error_list').insert({
bottom: new Element('li').update(error.key + ': ' + error.value)
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.