【问题标题】:i want to make a search in which i can search upper case and lower case both at same time..?我想进行搜索,我可以同时搜索大写和小写..?
【发布时间】:2019-05-10 05:55:42
【问题描述】:

问题陈述是我必须创建一个搜索功能,即使我输入小写或大写,我也可以搜索小写或大写元素

我尝试过大写搜索和小写搜索,但它根本不起作用,请尽快建议我

search(searchValue) {
    if (searchValue != null && searchValue != "") {
      var searchItem = searchValue;
      var allOppData = this.stagesWiseOpportunitiesData;

      var filtered = _.mapValues(allOppData, statuses =>
        _.filter(statuses, statusT =>
          _.some(statusT, T => _.includes(T, searchItem))
        )
      );
      this.stagesWiseOpportunitiesData = filtered;
      let stages = this.opportunitiesStateReason;
      stages.forEach(element => {
        let num = this.stagesWiseOpportunitiesData[element.orderData].reduce(
          function(sum, value) {
            return sum + value.expected_revenue;
          },
          0
        );
        element.totalExpectedRevenue = num.toFixed(2);
      });
    } else {
      this.stagesWiseOpportunitiesData = this.stagesWiseOpportunitiesDataCopy;
      let stages = this.opportunitiesStateReason;
      stages.forEach(element => {
        let num = this.stagesWiseOpportunitiesData[element.orderData].reduce(
          function(sum, value) {
            return sum + value.expected_revenue;
          },
          0
        );
        element.totalExpectedRevenue = num.toFixed(2);
      });
    }
  }
}

【问题讨论】:

  • 给我们一些例子和预期的输出
  • 例如,如果有一个元素名称为 test 的表,那么如果我搜索 (Test,TEST,test) 它必须显示结果 test 完全相同的功能run.stackblitz.com/api/angular/…
  • 您没有在搜索功能中返回任何内容。是这个错误吗?
  • 返回总和 + value.expected_revenue;我已经退回了这个
  • 好的,返回不正确。让我在答案中添加我的解决方案。我认为这可能是您的解决方案

标签: javascript angular typescript angular6


【解决方案1】:

试试这样。您错过了为search 函数返回的。

注意:您只返回了 search 函数内的函数

function search(searchValue) {
    if (searchValue != null && searchValue != "") {
        var searchItem = searchValue;
        var allOppData = this.stagesWiseOpportunitiesData;

        var filtered = _.mapValues(allOppData, statuses =>
            _.filter(statuses, statusT =>
                _.some(statusT, T => _.includes(T, searchItem))
            )
        );
        this.stagesWiseOpportunitiesData = filtered;
        let stages = this.opportunitiesStateReason;
        return stages.forEach(element => {
            let num = this.stagesWiseOpportunitiesData[element.orderData].reduce(
                function(sum, value) {
                    return sum + value.expected_revenue;
                },
                0
            );
            element.totalExpectedRevenue = num.toFixed(2);
        });
    } else {
        this.stagesWiseOpportunitiesData = this.stagesWiseOpportunitiesDataCopy;
        let stages = this.opportunitiesStateReason;
        return stages.forEach(element => {
            let num = this.stagesWiseOpportunitiesData[element.orderData].reduce(
                function(sum, value) {
                    return sum + value.expected_revenue;
                },
                0
            );
            element.totalExpectedRevenue = num.toFixed(2);
        });
    }
}

console.log(search("Test"))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2013-04-01
    • 2018-09-21
    • 2017-09-20
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    相关资源
    最近更新 更多