作者:汪健宜婉瑜 | 来源:互联网 | 2023-01-14 19:54
Ihaveascriptthatpullsinresultsanddisplaysitonmysite.Iwanttodisplayonlythelastth
I have a script that pulls in results and displays it on my site. I want to display only the last three results that are being pulled instead of everything. So the latest results are Test2
, Test1
and then Office 365 Planned Service.
我有一个脚本可以提取结果并将其显示在我的网站上。我想只显示被拉出的最后三个结果而不是一切。因此,最新的结果是Test2,Test1和Office 365计划服务。
Here are all the results being pulled:
以下是所有结果:
Here is my Javascript code:
这是我的Javascript代码:
$(document).ready(function(){
$pnp.setup({
baseUrl: "https://fh126cloud.sharepoint.com/TrainingResourceCenter/O365Training"
});
$pnp.sp.web.lists.getByTitle("O365RoadMap").items.orderBy("Created", false).get().then(function(items) {
console.log(items);
var result = items.map(item => {
return {
Title: item.Title,
Description: item.Description,
Link: item.Link
}
});
var $table = roadMapDisplay(result);
console.log($table);
$('#title').html($table);
});
function roadMapDisplay(items) {
var table = $('');
items.forEach(item => {
table.append(`${item.Title}`);
table.append(`${item.Description.slice(0, -200)}...
`);
table.append('
');
});
return table;
}
});
How could I throw a loop onto that function? I've tried so many different ways and have come short.
我怎么能在这个函数上抛出一个循环?我已经尝试了很多不同的方法而且做得很短。
Thanks all in advance!
提前谢谢!
5 个解决方案