javascript - 无法在 Jsplumb 社区版中添加节点或形状
问题描述
我正在使用他们的文档中提到的在我的应用程序@jsplumb/browser-ui
中创建一些。但我想在运行时创建节点。我做不到。Nodes
Nuxtjs/Vuejs
nodes/rectangle
每当用户单击Add Event
按钮时,我想创建形状。因此,Nodes
我不想创建静态方式,而是根据按钮单击动态/运行时间创建它。我不明白如何使用jsPlumb
文档来做到这一点,因为他们没有特定的代码示例来实现相同的目标。
以下是我的代码:
<template>
<div>
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<button class="btn btn-primary btn-sm" @click="addConnector()">
Add Connector
</button>
<button class="btn btn-primary btn-sm" @click="addNode()">
Add Event
</button>
<button class="btn btn-success btn-sm" @click="submitEvents()">
Submit
</button>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div id="diagram" ref="diagram" style="position: relative; width:100%; height:100%;" />
</div>
</div>
</div>
</div>
</template>
<script>
let jsPlumb = null
export default {
data () {
return {
nodeCounter: 0,
nodeArray: [],
connectorCounter: 0,
connectorArray: [],
allEventsInfoArray: []
}
},
async mounted () {
if (process.browser) {
const jsPlumbBrowserUI = await import('@jsplumb/browser-ui')
jsPlumb = jsPlumbBrowserUI.newInstance({
dragOptions: {
cursor: 'pointer',
zIndex: 2000
},
container: this.$refs.diagram
})
console.log(jsPlumb)
}
},
methods: {
// On click of Add Node button create the draggable node into the jsPlumb canvas
addNode () {
// const container = "<button class='btn btn-info' id='container_" + this.nodeCounter + "'></button>"
this.nodeCounter++
},
// On click of Add Connector button create the draggable node into the jsPlumb canvas
addConnector () {
console.log('Add Connector : ')
jsPlumb.connect({
anchor: 'AutoDefault',
endpoints: ['Dot', 'Blank'],
overlays: [
{ type: 'Arrow', options: { location: 1 } },
{
type: 'Label',
options: { label: 'foo', location: 0.25, id: 'myLabel' }
}
]
})
}
}
}
</script>
<style scoped>
</style>
解决方案
希望这个答案对将来的某人有所帮助:
根据贡献者GitHub的回复,我们无法Nodes/Shapes
在Jsplumb community edition
.
取而代之的是Jsplumb
,我开始使用DrawFlow
非常棒的库,它具有我的应用程序所需的所有要求。
推荐阅读
- javascript - Webpack 在 ES5 中生成箭头函数
- r - 如何在R中为不同类型的数据绘制趋势线?
- angular - 新大型项目Angular2上的内联样式代码
- python - Python matplotlib 覆盖轴
- android - 尝试使用 Kotlin 在 android studio 4.1 上创建应用程序时出错
- angular - 如何将 Docker 容器内的 node_modules 表单同步到 node_modules 文件夹外?
- java - 如何使用递归获取二叉搜索树中的所有非叶节点?
- java - 带有 JAVA 的 MQTT - 当使用 QoS1 发布一些数据时,我丢失了一些数据
- c - 找出 typedef 是否在 C 中定义了特定类型
- java - 使我的 switch 语句工作并打印到控制台