const inputOnchange = _debounce(async () => {
let value = inputRef.current.value
console.log('inputOnchange value:', value)
let searchLocationInfo = await searchLocation(AMap, value)
console.log('searchLocationInfo:', searchLocationInfo)
//相同的文本 字体蓝色
let setList = searchLocationInfo.map(el => {
return { ...el, nameColor: dimstyleStrColor(el.name, value, '#008EFF') }
})
setSearchlocation(setList)
}, 200)
const dimstyleStrColor = (str, label, color) => {
var reg = new RegExp("(" + label.replace(/([()])/g, "\\$1") + ")", "g");
var newstr = str.replace(reg, "<font color=" + color + ">$1</font>");
return newstr;
}
<div className='titleName' dangerouslySetInnerHTML={{ __html: item.nameColor }} />