问题描述
我正在尝试在我的 React 组件中添加预先输入,但它不起作用。这是我在 React 组件中添加 javascript 代码的方式。我已将它添加到我的 ComponentDidMount 中。
componentDidMount() {
const script = document.createElement("script");
script.type = "text/babel";
script.src = "../assets/js/plugins/typehead/bootstrap3-typeahead.min.js";
script.async = true;
console.log('Script',script);
document.onload = () => {
$(document).ready(function(){
$('.top_search_payer').typeahead({
source: ["United Health Group","Anthem","Aetna","Humana"]
});
$('.top_search_aff').typeahead({
source: ["Baylor University","UCLA Anderson","Mayo Clinic" ]
});
$('.top_search_geo').typeahead({
source: ["Option 1","Option 2","Option 3","Option 4"]
});
$('.top_search_spec').typeahead({
source: ["Rheumatology","Nephrology","Family Medicine","Hospitalist" ]
});
});
}
document.body.appendChild(script);
}
是否有另一种方法来执行此 javascript 代码,以便当我在框中键入内容时,应立即显示选项?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)