我从服务器发送的 JSON 是这样的:
data[
{"userFullName":"Tim, Bill","id":"LOt3","organisation":"FAP","loginSystem":"A","userId":0},{"userFullName":"Bruce, David","id":"LNA","organisation":"ES","loginSystem":"A","userId":0}
]
在我的 AJAX 调用成功后,我正在按如下方式处理数据:
success: function (data) {
javascript: console.log('data' + data);
$.each(data, function(key, value) {
javascript: console.log('id' + value.id);
$('#selectStaff').append('<option value="' + value.id+ '">' + value.userFullName + '</option>');
});
}
selectStaff 是 SELECT 控件的 ID...
SELECT 控件正在绘制,下拉列表中填充了“未定义”。
The console.log('data' + data)
打印以下行:
data[{"userFullName":"Tim, Bill","id":"LOt3","organisation":"FAP","loginSystem":"A","userId":0},{"userFullName":"Bruce, David","id":"LNA","organisation":"ES","loginSystem":"A","userId":0}]
但是,行 javascript:console.log('id' + value.id)
打印出 'UNDEFINED'
有人可以向我描述正确的语法吗?