假设我有一个名为“test”的列表 它有 5 个列表项(例如 a、b、c、d、e) 现在我在特定字段的列表项上手动应用过滤器 现在结果是 3 个列表项。
现在我想通过JavaScript读取这3个列表项的字段并对其进行计算。
我需要访问当前显示的字段(手动应用过滤器后)
我不想在 Javascript 中过滤它。但我想手动过滤某些字段,然后我想读取显示的结果。有人可以帮忙吗?
最佳答案
以下 jQuery 将获取显示的行的列的所有值。它适用于 SharePoint 2010。我让代码非常冗长并带有调试语句,以便更容易理解。请记住,除非删除 console.log
和 debugger
行,否则此代码不会在控制台关闭的情况下在 IE 中运行。
$(document).ready(function() {
var columnHeading = "Title";
var anchor = $("a").filter(function() {
return $(this).text() === columnHeading; //find the link that matches the text in the columnHeading variable
});
var th = anchor.closest("th"); //Get the parent table header
var columnIndex = th.index(); //Get the index of the table header in the row for use on other rows
var table = th.closest("table");
var i;
debugger;
table.find("tbody").first().find("tr").not(":first").each(function() { //Loop over every row in the table EXCEPT the first row because its the table header
i = $(this).find("td").eq(columnIndex); //find the td element at the index we determined earlier
console.log($(i).text()); //get the text in the td. You may need to parseInt before any mathematical formulas.
});
});
如果您需要澄清任何事情,请告诉我。
关于javascript - SharePoint - 使用 JavaScript 在应用过滤器后获取列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24858244/