首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角4-如何正确导入fancytree

角4-如何正确导入fancytree
EN

Stack Overflow用户
提问于 2019-07-15 13:11:13
回答 1查看 924关注 0票数 0

我正试图将fancytree导入到我的角4项目中。我按照这样的指示做了所有事情:https://github.com/mar10/fancytree/wiki/TutorialIntegration#howto-run-fancytree-with-angular-4

但最终每次我犯错误

$(.).fancytree不是函数

这条指令中缺少什么东西吗?

我到现在为止所做的:

  1. npm安装--保存jquery jquery.fancytree
  2. 将脚本和样式添加到角-cli.json中:
代码语言:javascript
复制
[...]
"styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
        "../node_modules/jquery.fancytree/dist/skin-win8/ui.fancytree.min.css",
        "styles.scss"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "../node_modules/bootstrap/dist/js/bootstrap.min.js",
        "../node_modules/jquery.fancytree/dist/jquery.fancytree-all-deps.min.js"
      ],
[...]
  1. 在tsconfig.app.json中添加类型:
代码语言:javascript
复制
{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "baseUrl": "",
    "types": ["jquery","jquery.fancytree"]
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}
  1. 在组件的html中添加了树id:
代码语言:javascript
复制
<div id="tree">

</div>
  1. 尝试在组件中使用:
代码语言:javascript
复制
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
// const fancytree = require('jquery.fancytree'); // doesn't work
import * as $ from 'jquery';

@Component({
  selector: 'table-of-content',
  templateUrl: './table-of-content.component.html',
  styleUrls: ['./table-of-content.component.scss']
})
export class TableOfContentComponent implements OnInit {

  @Output() isTocClosed: EventEmitter<boolean> = new EventEmitter<boolean>();

  constructor() { }

  ngOnInit() {
    $('#tree').fancytree({
      extensions: ['edit', 'filter'],
      source: [
        { title: "Node 1", key: "1" },
        {
          title: "Folder 2", key: "2", folder: true, children: [
            { title: "Node 2.1", key: "3" },
            { title: "Node 2.2", key: "4" }
          ]
        }
      ]
    });

    // const tree = fancytree.getTree('#tree');
  }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-15 14:13:31

好了找到了!这些是组件中真正需要的:

代码语言:javascript
复制
import 'jquery.fancytree/dist/modules/jquery.fancytree.edit';
import 'jquery.fancytree/dist/modules/jquery.fancytree.filter';

或者如果有人喜欢:

代码语言:javascript
复制
require('jquery.fancytree/dist/modules/jquery.fancytree.edit');
require('jquery.fancytree/dist/modules/jquery.fancytree.filter');

并在我们需要的组件中使用fancytree对象:

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

https://stackoverflow.com/questions/57040488

复制
相关文章

相似问题

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