我是AngularJs
的新手。我想突出显示上下文中的文本。我有以下代码
$scope.highlight = function(content, text, className, notByWordBoundry){
var RegExpEscapeText, str;
if (!(content && content.replace)) {
return '';
}
if (!text) {
return $sce.trustAsHtml(content);
}
if (!className) {
className = 'mark';
}
RegExpEscapeText = text.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&");
if (!notByWordBoundry) {
str = new RegExp('(\\b)' + RegExpEscapeText + '(\\b)','gi');
} else {
str = new RegExp(RegExpEscapeText,'gi');
}
return $sce.trustAsHtml(content.replace(str , '<span class=' + className + '>$&</span>'));
};
所以,我的上下文包含数据
a`bout any problems or issues and worked on design/enhancement and architecture .Client- java,spring,Jquery,jqgrid,hibernate,Ajax,Jboss,Mysql,eclipse,jira, pmd etc.`
因此,我的代码适用于所有内容。但我想强调client-
。
因为这不起作用。如果我删除了正则表达式并使用了&#34; text&#34;从输入到突出显示,然后它不突出显示来自上下文的正确单词。
例如 -
Is word , I want to highlight , so context is having Is word more than 3 times then whichever is the first gets highlighted . But I want to highlight the same word from the context .
任何人都可以帮我这个吗?
Here text is the value which is present in the context. I want to highlight that text.