【发布时间】:2020-10-02 13:15:22
【问题描述】:
来自 jquery-ui 的 Datepicker 没有出现在我的视图中。
应用程序.js
require('jquery');
require("jquery-ui/ui/widgets/datepicker");
环境.js
const webpack = require('webpack')
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery',
Popper: ['popper.js', 'default']
})
)
environment.toWebpackConfig().merge({
resolve: {
alias: {
'jquery': 'jquery/src/jquery'
}
}
});
在我看来
<script>
$(function() {
$('#reservation_start_date').datepicker({
dateFormat: 'dd-mm-yy' });
$('#reservation_end_date').datepicker({
dateFormat: 'dd-mm-yy' });
});
</script>
Chrome 控制台
jQuery.Deferred exception: $(...).datepicker is not a function TypeError: $(...).datepicker is not a function
Uncaught TypeError: $(...).datepicker is not a function
感谢大家的帮助!
解决了这样做: 我们必须将 jQuery 暴露给 window 对象:
packs/application.js
import JQuery from 'jquery';
window.$ = window.JQuery = JQuery;
【问题讨论】:
标签: jquery ruby-on-rails ruby jquery-ui jquery-ui-datepicker