1

我正在尝试在下拉列表中显示 XNAT 项目;但是,项目 id 的值被返回为未定义。我的代码是:

//populate the Project ID select
function populateProjectID() {
    alert("Populate project ID: ");
    $.ajax({
        type: 'GET',
        dataType : "json",
        url: XNAT_URL+'data/archive/projects/?format=json',
        xhrFields: {
            withCredentials: true
        },
        headers: {
            'Content-Type':'application/x-www-form-urlencoded',
        },
        success: function(response, status, xhr) {
            var responseObjArray = response.ResultSet.Result;
            alert("Populate project ID success: " + responseObjArray);
            for(var obj in responseObjArray){
                alert("responseObjArray[obj].project: " + responseObjArray[obj].project);
                $('<option style="color:black>').text(responseObjArray[obj].project).appendTo('#projectName');
            }

        },
        error: function(response) {
            alert("Populate project ID error: ");
            console.log(response)
        }
    });
}

"alert("填充项目ID成功:" + responseObjArray);" 返回:

Populate project ID success: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

警报 "alert("responseObjArray[obj].project: " + responseObjArray[obj].project);" 每次返回:

responseObjArray[obj].project: undefined

请问如何获取项目 ID 的值以填充下拉列表?

4

1 回答 1

1
responseObjArray[obj].project

应该

responseObjArray[obj].ID
于 2019-04-18T02:44:54.650 回答