我正试图将fancytree导入到我的角4项目中。我按照这样的指示做了所有事情:https://github.com/mar10/fancytree/wiki/TutorialIntegration#howto-run-fancytree-with-angular-4
但最终每次我犯错误
$(.).fancytree不是函数
这条指令中缺少什么东西吗?
我到现在为止所做的:
[...]
"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"
],
[...]{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"baseUrl": "",
"types": ["jquery","jquery.fancytree"]
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}<div id="tree">
</div>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');
}
}发布于 2019-07-15 14:13:31
好了找到了!这些是组件中真正需要的:
import 'jquery.fancytree/dist/modules/jquery.fancytree.edit';
import 'jquery.fancytree/dist/modules/jquery.fancytree.filter';或者如果有人喜欢:
require('jquery.fancytree/dist/modules/jquery.fancytree.edit');
require('jquery.fancytree/dist/modules/jquery.fancytree.filter');并在我们需要的组件中使用fancytree对象:
const fancytree = require('jquery.fancytree');https://stackoverflow.com/questions/57040488
复制相似问题