0

我有一个要求,我需要动态过滤列表查找。我的列表有一个名为的列category,可以包含 value 'A' or 'B'。然后有一个字段——'Selection'在 Content 类型上可以取值'A' or 'B' or 'All'。如果'A'我需要 List 查找来获取行 where category = 'A',同样适用'B'。但是,如果“选择”是 -'All'那么我需要显示列表中的所有项目。

我正在考虑过滤列的列表查找 - 'Category'。但问题是我在内容类型表单上,我没有任何可以动态设置的变量。

I can not use the Filter by control mapped to 'Selection'as the it does not work when the selection is 'All'(There is no value called 'All' under category in the list).

我尝试使用对公式进行运算的计算值,并尝试在按列表查找中的特定值过滤器中使用它,但过滤器不起作用,因为列表查找在表单加载计算值之前加载,因此计算值总是过滤为空。

有什么办法可以实现这个功能。

提前致谢

4

1 回答 1

1

对于这个问题,我想到了两种解决方案。

  1. 有 3 个独立的列表查找控件,它们相互重叠。一个按 A 过滤,一个按 B 过滤,让一个没有过滤器。然后创建规则以显示带有您要显示的过滤器的规则,并隐藏其他规则。要保存该值,当其中一个控件更改值时,您必须使用 JavaScript 将值从列表查找复制到隐藏的文本框中。如果您有更多选择,这个解决方案不是很好,而且会变得更糟......但它确实有效。

  2. 您可以使用 JavaScript 根据选择过滤列表。这有点棘手,但您不需要更多的查找控件来获得更多选项。无论类别/选择有多少选项,您都只需要 2 个列表查找。您需要一个显示您希望用户从中选择的信息(未过滤),另一个来自同一个列表和同一个视图,但该列应该是 Category 列(您可以使用 javascript 隐藏此查找)。这是我用来获取您所描述内容的代码。

    //get the original html to 'reset' the dropdown after a change  
    var originalTitle = NWF$("#" + title).html();
    
    //when the selection changes
    NWF$("#" + selection).change(function () {
    
    //put the original html in the dropdown to check all the options
    NWF$("#" + title).html(originalTitle);
    
    //get the new value of the selection
    var choice = NWF$("#" + selection + " :checked")[0].value
    
    //if choice is all then we are done because the original html is in the dropdown again with all the options
    if (choice == "All") {
        return;
    }
    
    //create the array where you will store the ids of the options that match the choice
    var filteredIds = [];
    
    //for each option in the category drop down, see if the text matches the choice (this is your filtering)
    NWF$("#" + categoryDD + " option").each(function (i, n) {
    
        //if the text of the option matches the choice add the id to the array. 
        if (n.text == choice) {
            filteredIds.push(n.value);
        }
    });
    
    //initialize string of html
    var filteredTitlesHTML = ""
    
    //for each of the ids in the list, get the option html with that id from the title dropdown and add it to the resulting HTML string
    NWF$(filteredIds).each(function (i, n) {
        filteredTitlesHTML += NWF$("#" + title + " option[value = '" + n + "']")[0].outerHTML
    })
    
    //put the html in the dropdown to show only filtered values
        NWF$("#" + title).html(filteredTitlesHTML);
    })
    

    这显示了我使用的字段,标签是我给它们的 javascript 变量名

您可以在图片中看到我为控件提供的 javascript 变量名称以使用我提供的 javascript。

于 2015-03-26T14:24:46.917 回答