【发布时间】:2016-05-05 19:48:46
【问题描述】:
我的 CoffeeScript
errorList = @state.errors.responseText
for own key, value of errorList
console.log "#{key} -> #{value}"
我的errorList变量={"link":["is invalid"]}
当我运行此代码时,在输出中迭代此错误列表中的每个字符。如何获得“链接 -> 无效”?
【问题讨论】:
-
"#{key} -> #{value[0]}"? -
您是否确保
responseText被解析为JSON?听起来您正在遍历字符串而不是对象。如果您使用 jQuery 并且需要旧版浏览器支持,请使用errorList = JSON.parse(@state.errors.responseText)或$.parseJSON。
标签: javascript ruby-on-rails json coffeescript