以下是我为使其发挥作用而采取的步骤。
我从一个新的 cli 应用程序开始。
npm install --save jquery jstree
npm install --save-dev @types/jquery @types/jstree
然后我更新了angular.json
文件,如果您使用的是旧版本的 angular-cli,请更改angular-cli.json
文件。我添加了"../node_modules/jstree/dist/themes/default-dark/style.min.css"
到 styles 属性数组。
我还在脚本属性数组中添加了两项:
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/jstree/dist/jstree.min.js"
然后我更新了src/app/app.component.html
to
<div id="foo">
<ul>
<li>Root node 1
<ul>
<li>Child node 1</li>
<li><a href="#">Child node 2</a></li>
</ul>
</li>
</ul>
</div>
我也更新src/app/app.component.ts
to
import { Component, OnInit } from '@angular/core';
declare var $: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
ngOnInit(): void {
$('#foo').jstree();
}
}
希望这可以帮助!