我从php传递给js对象。例如:
{"3199":{"name":"Ramona RONDEREGGER","mail":"mona.schlaepfer@bluewin.ch","phone":null,"hope":null
,"status":"NEW LEAD"},"3253":{"name":"Olivia
BAUMANN","mail":"oliviazurfluh@gmail.com","phone":null,"hope"
:null,"status":"NEW LEAD"}}
我想在js中获取此对象的数据(获取3199,3253及其数据(名称,邮件...)。 我该怎么做? 我试试看:
$(data).each(function(key,value){
$(value).each(function(key,value){
console.log(value);
});
});
但是id不起作用 请帮我解决这个问题 感谢
答案 0 :(得分:1)
遍历您的对象并按键获取数据。以下是数据集的示例,显示了如何访问结果对象中的数据。
var data = {"3199":{"name":"Ramona RONDEREGGER","mail":"mona.schlaepfer@bluewin.ch","phone":null,"hope":null
,"status":"NEW LEAD"},
"3253":{"name":"Olivia BAUMANN","mail":"oliviazurfluh@gmail.com","phone":null,"hope"
:null,"status":"NEW LEAD"}};
for(x in data){
// this will print your key
console.log("this is your key " + x);
// this line will print your key object
console.log(data[x]);
//to access internal element
console.log(data[x]['mail']);
}

答案 1 :(得分:0)
指定此value["3199"]
var data = {"3199":{"name":"Ramona RONDEREGGER","mail":"mona.schlaepfer@bluewin.ch","phone":null,"hope":null,"status":"NEW LEAD"},"3253":{"name":"Olivia BAUMANN","mail":"oliviazurfluh@gmail.com","phone":null,"hope"
:null,"status":"NEW LEAD"}};
$(data).each(function(key,value){
$(value).each(function(key,value){
console.log(value["3199"]);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>