-1

我从服务器发送的 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'

有人可以向我描述正确的语法吗?

4

1 回答 1

1

您的代码中的错误val.id

工作正常

小提琴

脚本

    var user=[{"userFullName":"be, apple","id":"xdsd3","organisation":"FL ","userId":0},{"userFullName":"Mack, David","id":"lol323","organisation":"ES","userId":0}]

$.each(user, function(key, value) {
   console.log('id' + value.id);
                            $('#selectStaff').append('<option value="' + value.id + '">' + value.userFullName + '</option>');
                        });
于 2013-11-08T06:37:13.047 回答