【问题标题】:Exception from Tracker afterFlush function: TypeError: $(...).calendar is not a function来自 Tracker afterFlush 函数的异常:TypeError: $(...).calendar is not a function
【发布时间】:2017-03-21 23:19:47
【问题描述】:

我正在尝试将此 npm 包 (https://www.npmjs.com/package/semantic-ui-calendar) 与 Meteor 一起使用,但在浏览器控制台中出现此错误:

来自 Tracker afterFlush 函数的异常:TypeError: $(...).calendar 不是函数

我尝试了以下安装来修复此错误:

npm i semantic-ui-calendar
npm semantic-ui-calendar --save
meteor npm i semantic-ui-calendar
meteor npm semantic-ui-calendar --save

我的代码:

blaze-html-模板:

<template name="myTemplate">    
  <h3>Date only</h3>
  <div class="ui calendar" id="example2">
    <div class="ui input left icon">
      <i class="calendar icon"></i>
      <input type="text" placeholder="Date">
    </div>
  </div>
  <br/>
</template>

js-模板文件:

Template.myTemplate.onRendered(function() {
    $(document).ready(function() {
        $('#example2').calendar({
          type: 'date'
        });
    });
});

还将此 JQuery 代码从 onRendered 移至帮助程序 - 没有成功。

【问题讨论】:

    标签: meteor meteor-blaze semantic-ui


    【解决方案1】:

    你试过了吗

    npm install --save semantic-ui-calendar
    

    然后通过将以下内容放在文件顶部来从包中导入文件。

    import { ... } from 'semantic-ui-calendar'
    

    【讨论】:

    • 使用 import { ... } from 'semantic-ui-calendar'; 我得到 "Unexpected token (2:9)" 因为 { ... } 。我将{ ... } 更改为{ Calendar }import { Calendar } from 'semantic-ui-calendar';,我现在得到“未捕获的错误:找不到模块'semantic-ui-calendar'(...)”
    猜你喜欢
    • 2019-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-24
    相关资源
    最近更新 更多