caught TypeError: Cannot read properties of undefined (reading 'Link')
,即使它是在 Sharepoint 列表中定义的
var build_newQuickLinks = function (items) {
var newQuickLinksSection = $("#quickLinkItems");
console.log(newQuickLinksSection)
//var start = Math.max(0, items.length - 4);
for (let i = 0; i < 10; i++) {
let quickLinks = items[i].Link != null ?
'<a target="_blank" href='+ items[i].Link.Url +' class="btn btn-tag btn-rounded" data-mdb-close="true">' +
'<div class="d-flex align-items-center align-content-center justify-content-left"><i class="'+ items[i].Icon +'"></i><span class="text-truncate">'+ items[i].Title +'</span></div></a>'
: ''
newQuickLinksSection.append(quickLinks);
}
}
//ajax call
$(document).ready(function () {
$.ajax({
url: apiUrlQuickLinks,
method: "GET",
headers: {
Accept: "application/json; odata=verbose"
},
success: function (data) {
var items = data.d.results;
console.log(items)
// only check out the data here. like, Array.isArray(items)
// call different function to do
build_newQuickLinks(items);
},
error: function (data) {
console.log("Error: " + data);
}
});
});
这是我用来在 Sharepoint 中调用列表的 Javascript 代码。我尝试将
null
更改为 undefined
但我仍然得到相同的结果。这些项目按预期显示在页面上,但我仍然在控制台中收到该消息。
https://www.broward.org/playground/carlos/Pages/Demo-2.aspx