我想进行搜索,使我可以同时搜索大写和小写。

时间:2019-05-10 05:55:42

标签: javascript angular typescript angular6

问题陈述是,我必须搜索一个函数,即使我键入小写字母或大写字母,我也可以搜索小写字母和大写字母

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

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);
      });
    }
  }
}

1 个答案:

答案 0 :(得分:0)

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

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

中的一个函数

 函数search(searchValue){
    if(searchValue!= null && searchValue!=“”){
        var searchItem = searchValue;
        var allOppData = this.stagesWiseOpportunitiesData;

        var filter = _.mapValues(allOppData,statuss =>
            _.filter(statuses,statusT =>
                _.some(statusT,T => _.includes(T,searchItem))
            )
        );
        this.stagesWiseOpportunitiesData =已过滤;
        让stage = this.opportunitiesStateReason;
        返回stage.forEach(element => {
            让num = this.stagesWiseOpportunitiesData [element.orderData] .reduce(
                函数(总和,值){
                    返回总和+ value.expected_revenue;
                },
                0
            );
            element.totalExpectedRevenue = num.toFixed(2);
        });
    }其他{
        this.stagesWiseOpportunitiesData = this.stagesWiseOpportunitiesDataCopy;
        让stage = this.opportunitiesStateReason;
        返回stage.forEach(element => {
            让num = this.stagesWiseOpportunitiesData [element.orderData] .reduce(
                函数(总和,值){
                    返回总和+ value.expected_revenue;
                },
                0
            );
            element.totalExpectedRevenue = num.toFixed(2);
        });
    }
}

console.log(search(“ Test”))