【问题标题】:SharePoint - Use JavaScript to get the list items after filter is appliedSharePoint - 应用过滤器后使用 JavaScript 获取列表项
【发布时间】:2014-07-21 05:30:16
【问题描述】:

假设我有一个名为“测试”的列表 它有 5 个列表项(比如 a、b、c、d、e) 现在我在特定字段的列表项上手动应用过滤器 现在结果是 3 个列表项。

现在我想通过 JavaScript 读取这 3 个列表项的字段并对其进行计算。

我需要访问当前显示的字段(手动应用过滤器后)

我不想在 Javascript 中过滤它。但我想手动过滤一些字段,然后我想读取显示的结果。谁能帮忙?

【问题讨论】:

    标签: javascript sharepoint filter field listitem


    【解决方案1】:

    下面的 jQuery 将为显示的行获取列的所有值。它适用于 SharePoint 2010。我让代码非常冗长,并带有调试语句,因此更容易理解。请记住,除非您删除 console.logdebugger 行,否则此代码不会在控制台关闭的 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.
        });
    });
    

    如果您需要澄清任何事情,请告诉我。

    【讨论】:

    • 非常感谢您的帮助。 !!现在我想读取索引处的所有 td 元素。如何做呢 ?意思是,我想读取显示的列表项的所有字段值。
    • 您能说明一下您想做什么吗?您是在问如何读取一行中的所有值或一列中的所有值?我的示例展示了如何读取列中的所有值(.each 循环遍历所有行并从列中读取值)。
    • 是的,它正在读取列值,对于每一行我有 5 个字段。对于每一行,我想读取每个字段值并将其存储在一个数组中。到目前为止,我使用 $(i).next().next() 得到了它。但是迭代需要很多时间。需要有效的逻辑。提前致谢
    猜你喜欢
    • 1970-01-01
    • 2018-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    • 1970-01-01
    相关资源
    最近更新 更多