将用户文本发布到网页(使用Mongodb和节点以及js)时,我试图突出显示与商店阵列中商店名称匹配的任何文本。通过数据库循环,并发布到网页代码:突出显示匹配文本
<% posts.forEach(function(post) { %>
<div class="post">
<h4 class="date">
<span><%= post.created.toDateString() %></span>
</h4>
<p class="post_text"><%- post.body %></p>
</div>
<% }); %>
我有我用来匹配从一个数组的话一些练习的js控制台的代码,但我有困难与把文字重新走到一起与突出显示的单词前进(S)。 2个字商店名称是另一个问题...
var blogInput = "We went to target last night, also to publix";
var array1 = blogInput.split(" ");
var array2 = ["kroger", "lums", "marlows", "eats", "burger king",
"home", "wendys", "publix", "donut circus", "jewelry store",
"target"];
function getMatch(a, b) {
var matches = [];
for (var i = 0; i < a.length; i++) {
for (var e = 0; e < b.length; e++) {
if (a[i] === b[e]) {
var x = a[i];
matches.push(x);
}
}
}
return matches;
}
getMatch(array1, array2);
(2) ["target", "publix"]
使用这个例子,然后我想将字符串句子重新走到一起,并发布到页面与“目标”和蓝色“域名后缀”文本。任何提示或智慧的话都会有帮助。谢谢!