【问题标题】:Meteor app bootstrap scrollspy errorMeteor app bootstrap scrollspy 错误
【发布时间】:2016-03-05 12:48:10
【问题描述】:

拥有一个带有 Bootstrap 的 Meteor 应用程序(手动插入到 public/javascript 目录中)。每次执行应用程序时,我都会得到以下信息:

Exception from Tracker afterFlush function:
debug.js:41 TypeError: $(...).scrollspy is not a function
    at eval (eval at <anonymous> (http://localhost:3000/packages/jquery.js?1015953f785c9b76503e2ecb391507dce965f357:365:22), <anonymous>:20:15)
    at eval (eval at <anonymous> (http://localhost:3000/packages/jquery.js?1015953f785c9b76503e2ecb391507dce965f357:365:22), <anonymous>:48:3)
    at eval (native)
    at http://localhost:3000/packages/jquery.js?1015953f785c9b76503e2ecb391507dce965f357:365:22
    at Function.jQuery.extend.globalEval (http://localhost:3000/packages/jquery.js?1015953f785c9b76503e2ecb391507dce965f357:366:7)
    at jQuery.ajaxSetup.converters.text script (http://localhost:3000/packages/jquery.js?1015953f785c9b76503e2ecb391507dce965f357:9792:11)
    at ajaxConvert (http://localhost:3000/packages/jquery.js?1015953f785c9b76503e2ecb391507dce965f357:8864:18)
    at done (http://localhost:3000/packages/jquery.js?1015953f785c9b76503e2ecb391507dce965f357:9285:15)
    at callback (http://localhost:3000/packages/jquery.js?1015953f785c9b76503e2ecb391507dce965f357:9739:8)
    at Object.send (http://localhost:3000/packages/jquery.js?1015953f785c9b76503e2ecb391507dce965f357:9745:7)

我检查了 'public/javascript/bootstrap.js' 文件并且有一个函数 'ScrollSpy(element, options)' 所以 它似乎是一个函数。因此,不知道这里出了什么问题......

编辑:

我正在将文件加载到 layout.js 文件中:

Template.layout.rendered = function() {
  $('head').append('<script type="text/javascript" src="/frontend/javascript/jquery.easing.min.js"></script>');
  $('head').append('<script type="text/javascript" src="/frontend/javascript/jquery.easing.min.js"></script>');
  $('head').append('<script type="text/javascript" src="/frontend/javascript/jquery.fittext.js"></script>');
  $('head').append('<script type="text/javascript" src="/frontend/javascript/wow.min.js"></script>');
  $('head').append('<script type="text/javascript" src="/frontend/javascript/creative.js"></script>');
}

奇怪的是我没有加载引导 javascript,但我仍然获得引导布局和功能。在上面的 layout.js 中加载最小化的引导程序会导致没有导航菜单(它在那里但不显示)

编辑:目录结构

client
  helpers
  lib
    frontend
       css
templates
  authenticated
  layouts
  public   
lib
public
  frontend
     fonts
     img
     javascript
server
   ...

【问题讨论】:

  • 公共文件不会自动加载到应用程序中。您是否在任何地方都包含这些脚本?

标签: twitter-bootstrap meteor


【解决方案1】:

公共文件不会自动加载到应用程序中,您需要手动包含它们。 This Stackoverflow answer 提供有关如何包含外部脚本的详细信息。公共目录中的文件可以使用绝对 url 访问:/javascript/bootstrap.js

我建议只使用 Bootstrap 包,但是您可以使用:meteor add twbs:bootstrap 安装它。有关该软件包的更多信息,请访问Atmosphere, the package browsing site for Meteor

【讨论】:

  • 我编辑了原始问题,并提供了有关加载 javascript 文件的更多信息。在使用流星添加 twbs:bootstrap 我在这里(manuel-schoebel.com/blog/…)读到这不是正确的方法。注意:我正在将一个名为 Creative 的预制引导主题集成到我的应用程序中,如果我不包含 Bootstrap js 文件(但随后出现 scrollspy 错误),它可以正常工作。如果我加载 bootstrap.js 我没有菜单。
  • 你的应用的目录结构是什么?因为/frontend 不是人们通常在他们的应用程序中使用的路径。另外,我没有看到您在该代码中包含bootstrap.js 文件。
  • 我在原始问题中添加了目录结构。确实,我正在使用前端,因为我想为前端和后端设置单独的布局。如果我不包含 bootstrap.js 文件,一切正常,但是当我这样做时,我没有导航菜单。
  • 好的,我想我明白你的问题是什么了。引导 css 在客户端/lib/前端?那会自动加载。 Bootstrap 样式可以在没有 Bootstrap javascript 的情况下正常工作,但要让 scrollspy 工作,您需要包含 bootstrap.js 文件。
  • 确实,您遇到了问题。但是,如果我加载 bootstrap.js 文件,如果我不添加 bootstrap.js 文件,我的导航菜单会在它工作时消失。我认为 js 和 css 通常不会踩到对方的脚趾 :-)。有什么想法吗?
猜你喜欢
  • 1970-01-01
  • 2012-12-30
  • 2016-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多