XNAT JSON获取项目ID列表,以填充下拉列表供选择

时间:2019-04-15 05:55:06

标签: jquery json xnat

我正在尝试在下拉列表中显示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的值来填充下拉菜单?

1 个答案:

答案 0 :(得分:1)

responseObjArray[obj].project

应该是

responseObjArray[obj].ID