首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >tablesorter不是函数rails 6错误

tablesorter不是函数rails 6错误
EN

Stack Overflow用户
提问于 2022-03-28 12:14:08
回答 1查看 83关注 0票数 1

我试图向我的表中添加tablesorter,但最后在浏览器控制台上出现了以下错误。Uncaught TypeError: n(...).tablesorter is not a function,这是我的application.js

代码语言:javascript
复制
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.

import Rails from "@rails/ujs"
import * as ActiveStorage from "@rails/activestorage"
require('jquery')
import "channels"
import "cocoon";
import "chartkick/chart.js"
import tablesorter from 'tablesorter/dist/js/jquery.tablesorter'
Rails.start()
ActiveStorage.start()

import 'bootstrap/dist/js/bootstrap'
import 'bootstrap/dist/css/bootstrap'
import '../stylesheets/application'
import "@fortawesome/fontawesome-free/js/all"

require("stylesheets/application")

$(function () {
    $('.tablesorter').tablesorter({
    showProcessing: true,
    // initialize zebra and filter widgets
    widgets: ["zebra", "filter"],
    headers: {
      0: { sorter: false, filter: false },
      13: { sorter: true, filter: true }
    }
  });
})

我在Gemfile jquery-tablesorter中添加了gem。我也做过yarn add jqueryyarn add tablesorter,但是我仍然被困住了。

注意:jquery-tablesorter是我在Gemfile中拥有的唯一与jquery相关的gem。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-29 07:12:41

我不知道$是在哪里装载的。Tablesorter没有权限定义tablesorter函数。您需要显式导入它。

代码语言:javascript
复制
import jQuery from "jquery";
import "tablesorter/dist/js/jquery.tablesorter";
window.$ = window.jQuery = jQuery;

代码语言:javascript
复制
window.$ = window.jQuery = require("jquery");
require("tablesorter/dist/js/jquery.tablesorter");
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71647298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档