在 ajax 调用后,我的数据中有 json 对象,如
[
{
"_id": {
"$id": "58d8e2831d7859e80d000033"
},
"broadcast_id": 70,
"studentList": "",
"employeeList": "999",
"mailTitle": "adsf",
"broadcastMessage": "dsfsdf dsd fgd",
"emailSent": "0",
"userdetails": []
},
{
"_id": {
"$id": "58d8eaba1d7859c81300002e"
},
"broadcast_id": 72,
"studentList": "",
"employeeList": "999|788",
"mailTitle": "Hekjh",
"broadcastMessage": "hhyky jk",
"emailSent": "0",
"userdetails": []
},
{
"_id": {
"$id": "58dde8ed1d78597011000029"
},
"user_id": 1,
"broadcast_id": 76,
"studentList": "",
"employeeList": "999|788",
"mailTitle": "Hello",
"broadcastMessage": "How are u ",
"emailSent": "0",
"dateSent": "31/03/2017",
"userdetails": [
{
"_id": {
"$id": "568f95dc99fbadb016000029"
},
"uid": 1,
"username": "test",
"password": "LeLafe#7861",
"email_id": "sales@lelafe.com",
"creation_date": "",
"role": "admin",
"is_enabled": 1
}
]
}
]
现在我正在尝试解析嵌套的 json 属性userdetails,以便在表格中发挥作用并将其显示。我尝试过以下几行
$.ajax({
url: 'index.php?action=fetchBroadcastedMessageList',
type: 'POST',
dataType: 'JSON',
data: { usertype: usertype },
success: function(data) {
for (var i in data) {
$("#broadcastedmessagelist").append('<tr>' +
'<td style="text-align: center;">' +
'' + data[i].userdetails["role"] + '' +
'</td>'...
);
}
});
}
行data[i].userdetails["role"]
没有检索到相应的 Angular 色
只要有可用的用户详细信息,就具有值(value)。请帮我 !!!
最佳答案
你也可以这样使用
$.ajax({
url: 'index.php?action=fetchBroadcastedMessageList',
type: 'POST',
dataType: 'JSON',
data: {usertype: usertype},
success: function (data) {
$.each(data , function(key,value)) {
$("#broadcastedmessagelist").append('<tr>' +
'<td style="text-align: center;">' +
'' + value.userdetails[0]["role"] + '' +
'</td>'...
);
}
});
}
关于javascript - 嵌套 JSON 数组对象代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43247962/