[英]Js foreach with key=>value
if (json['error'])
{
for(var arg in json['error']) {
$("#e-"+key).html(value);
}
}
I have an array $json['error'] I need to get key and edit by jquery using value of this array. 我有一个数组$ json ['error']我需要获取键并使用此数组的值通过jquery进行编辑。 How can I do this?
我怎样才能做到这一点? Thanks!
谢谢!
You can you for in
loop like this: 您可以这样
for in
循环:
for(var arg in json['error']) {
//arg is the prop
// json['error'][arg] is the value
$("#e-"+arg).html(json['error'][arg]);
}
( json['error']
should be a JS object ) (
json['error']
应该是一个JS对象)
OK. 好。 it's just a problem of knowing js)
这只是了解js的问题)
var err = json['error'];
for(var arg in err) {
$("#e-"+arg).html(err[arg]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.