vis.js 网络 regeneratorRuntime 未定义 [regeneratorRuntime 未定义] Salesforce 中的错误

vis.js Network regeneratorRuntime is not defined [regeneratorRuntime is not defined] error in Salesforce

尝试在 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

这是我认为可以解决您的问题的方法。

第一种方法(仅当库小到足以作为 LWC 组件上传时)

您需要创建两个 LWC 组件:

  • 我的网络
    • myNetwork.js
    • myNetwork.html
    • 我的网络。js-meta.xml
  • visNetworkLib

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,
        }, {})
    }
}

我已经弄明白了,你必须加载 vis-data 与 vis-network 分开。你可以在这里找到我基于 NPSP 关系和 NPSP 隶属关系的工作示例。 https://github.com/mrainboldt/visNetworkMapLWC