【发布时间】:2018-08-26 18:15:59
【问题描述】:
我正在尝试在我的反应应用程序中使用第三方插件,例如 bootstrap-tagsinout 和 noUiSlider。我已经通过 npm 将库安装到我的 package.json 中。目前我正在我的 componentDidMount 方法中初始化插件。我就是这样做的
componentDidMount = () => {
$(document).ready(function() {
// Apply the plugin to the element
$("#ionSlider-newTag").ionRangeSlider({
min: 0,
max: 5000,
type: 'double',
postfix: 's',
maxPostfix: "+",
prettify: false,
hasGrid: true,
from: 1600,
to: 2950
});
});
$(document).ready(function() {
$('#tagsinput').tagsinput({
typeahead: {
source: ['Smoking, Drinking, Eating']
}
});
});
$(document).ready(function() {
// Apply the plugin to the element
$("#noUiSlider").noUiSlider({
start: 40,
connect: "lower",
range: {
'min': 0,
'max': 100
}
});
});
这是我的标签输入 div
<div className="form-group form-group-default">
<label>Tags</label>
<input id="#tagsinput" type="text" value="Smoking,Drinking" data-role="tagsinput"/>
</div>
当我运行它时,我得到一个错误提示
index.js:121 Uncaught TypeError: $(...).tagsinput is not a function
和
index.js:121 Uncaught TypeError: $(...).noUiSlider is not a function
我在我的 react 组件中导入了插件
import 'ion-rangeslider'
import 'bootstrap-tagsinput'
import 'nouislider'
import $ from 'jquery'
我已经查找了所有已经存在的问题并尝试了它们。但没有任何效果。我做错了什么?
更新
我尝试使用 refs,但没有帮助
<input id="#tagsinput" type="text" ref={(input) => {textInput = input; }} value="Smoking,Drinking" data-role="tagsinput"/>
textInput.tagsinput({
typeahead: {
source: ['Smoking, Drinking, Eating']
}
});
但是我收到了这个错误
Uncaught TypeError: Cannot read property 'tagsinput' of undefined
【问题讨论】:
标签: javascript reactjs twitter-bootstrap-3 nouislider bootstrap-tags-input