尝试在 Salesforce 中使用 vis.js 网络库我在 LWC 和具有 api 版本 40.0 的 Aura 组件中都尝试过,但我收到 regeneratorRuntime 未定义 [regeneratorRuntime 未定义] 尝试使用https://unpkg.com/browse /vis-network@8.1.0/standalone/umd/vis-network.min.js
问问题
200 次
2 回答
0
这是我认为可以解决您的问题的方法。
第一种方法(仅当库足够小以作为 LWC 组件上传时)
您需要创建两个 LWC 组件:
- 我的网络
- myNetwork.js
- 我的网络.html
- myNetwork.js-meta.xml
- visNetworkLib
- visNetwork.js = esm /vis-network.min.js的内容
- visNetwork.js-meta.xml
import { LightningElement } from 'lwc'
import { DataSet, Network } from 'c/visNetworkLib'
export default class MyNetwork extends LightningElement {
nodes = null
edgeds = null
renderedCallback () {
this.nodes = new DataSet([
{id: 1, label: 'Node 1'},
{id: 2, label: 'Node 2'},
{id: 3, label: 'Node 3'},
{id: 4, label: 'Node 4'},
{id: 5, label: 'Node 5'},
])
this.edges = new DataSet([
{from: 1, to: 3},
{from: 1, to: 2},
{from: 2, to: 4},
{from: 2, to: 5},
{from: 3, to: 3},
])
const container = this.template.querySelector('div.myNetwork')
this.network = new Network(container, {
nodes: this.nodes,
edges: this.edges,
}, {})
}
}
<template>
<div
lwc:dom="manual"
class="myNetwork"
></div>
</template>
第二种方法
创建一个静态资源名称 visNetwork 即上传的vis-network.min.js
然后像这样在 myNetwork.js 中加载它
import { LightningElement } from 'lwc'
import { ShowToastEvent } from 'lightning/platformShowToastEvent'
import visNetworkUrl from '@salesforce/resourceUrl/visNetwork'
import { loadScript } from 'lightning/platformResourceLoader'
export default class MyNetwork extends LightningElement {
nodes = null
edgeds = null
visLoaded = false;
renderedCallback() {
if (!this.visLoaded) {
this.visLoaded = true;
loadScript(this, visNetworkUrl).then(() => {
this.initializeNetwork();
})
.catch(error => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Error loading vis network',
message: error.message,
variant: 'error'
})
);
});
}
}
initializeNetwork () {
this.nodes = new DataSet([
{id: 1, label: 'Node 1'},
{id: 2, label: 'Node 2'},
{id: 3, label: 'Node 3'},
{id: 4, label: 'Node 4'},
{id: 5, label: 'Node 5'},
])
this.edges = new DataSet([
{from: 1, to: 3},
{from: 1, to: 2},
{from: 2, to: 4},
{from: 2, to: 5},
{from: 3, to: 3},
])
const container = this.template.querySelector('div.myNetwork')
this.network = new Network(container, {
nodes: this.nodes,
edges: this.edges,
}, {})
}
}
于 2020-08-21T12:00:38.127 回答
0
我已经想通了,你必须加载 vis-data 与 vis-network 分开。你可以在这里找到基于 NPSP 关系和 NPSP Affiliations 的工作示例。 https://github.com/mrainboldt/visNetworkMapLWC
于 2020-08-29T03:23:03.910 回答