[英]Unable to add Nodes or shapes in Jsplumb community edition
我正在使用@jsplumb/browser-ui
在我的Nuxtjs/Vuejs
應用程序中創建一些Nodes
,如他們的文檔中所述。 但我想在運行時創建節點。 我做不到。
每當用戶單擊“ Add Event
按鈕時,我都想創建nodes/rectangle
形狀。 因此,我不想以靜態方式創建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的回復,我們無法在Jsplumb community edition
創建Nodes/Shapes
。
我開始使用DrawFlow
庫而不是Jsplumb
,它非常棒並且具有我的應用程序所需的所有要求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.