BackEnd/Node.js

검색시 하이라이트

철철22 2018. 7. 26. 09:35
반응형

검색시 하이라이트를 주는 기능을 구현하는 코드


      hightlight(value: any, type){      
        if (this.searchType != type) { // 검색 타입비교
          return value;
        }
   
        if(this.searchKeyword.length>0){
        let match = value.match(this.re); //this.re = 검색어 
        // 공백 처리 & + 처리
        this.re = new RegExp(this.searchKeyword.replace(/ /gi,"").split('').join("\\s*").replace(/\+/gi,"\\\+"),'gi');

          if (!match) {
            return value;
          }else{
            const res = value.replace(this.re, "" + match[0] + "")
            return res;
          }
        }
      }
css
.highlight{
  background: #f1c40f;
}




C++ 검색


전 쟁 검색


반응형