gpt4 book ai didi

javascript - Sharepoint - REST API 查询字段的结果未定义

转载 作者:行者123 更新时间:2023-11-27 22:48:14 24 4
gpt4 key购买 nike

我正在使用 REST/JS 调用来填充某个列表项中的某些字段。我在获取某些字段时遇到了麻烦,因为它们在显示结果时显示为未定义。但我注意到,显示为未定义的字段是类型:Lookup、Person 或 Group 或 Choice。显示的类型有单行文本、日期和时间以及数字。我浏览了一篇又一篇文章,但一直无法弄清楚。这是我正在讨论的一些代码的片段:

$(function() {

$.ajax({
url: "__URL__/_api/lists/getbytitle('Master%20Project%20List')/items?&$filter=Number eq '" + projectId + "'",
headers: {"Accept": "application/json;odata=verbose"},
type: "GET",
cache: false,
async: false,

}).success(function (data) {
$.each(data.d.results, function(key, value) {

//Project Title
console.log("TEST TITLE - " + value.Title);
Title = "*" + value.Title;

//Project Divison
console.log("TEST DIVISION - " + value.Div);
division = "*" + value.Div;

});
});
});

这是一个类似的帖子:https://sharepoint.stackexchange.com/questions/147909/some-fields-undefined-when-display-results-from-rest-query

最佳答案

您可能需要使用 $select$expand 选项显式请求所需的字段值。

$expand 选项指定返回连接列表中的投影字段。

请考虑以下摘录自 SharePoint 2013 - Understanding the SharePoint 2013 REST Interface作者:吉姆·克劳利和瑞奇·柯卡姆:

When a SharePoint list has a lookup field to another list, this effectively serves as a join of the two lists. You can use the $expand option to return projected fields from the joined list. For example, if the Books list has a PublishedBy field that looks up to the Name field of a Publisher list, you can return those names with this URL:

_api/web/lists/getByTitle(
'Books')/items?$select=Title,PublishedBy/Name&$expand=PublishedBy

Notice that you reference the column in the foreign list by using the syntax lookup_column_display_name/foreign_column_name, not foreign_list_name/foreign_column_name. It’s also important to note that you can’t select a lookup field name without also expanding it.

有关更多示例,请参阅 this question 给出的答案在 SharePoint Stack Exchange 网站上。

关于javascript - Sharepoint - REST API 查询字段的结果未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38253594/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com