2014-01-23 55 views
1

要操縱標記爲的圖,我想我需要在jsPlumb連接的每個標籤上添加一個附加屬性。例如,當我點擊連接標籤時,即使源標籤點和目標標籤點可以從標籤標識(或屬性)中推導出來,我也無法知道哪種類型的標籤點擊過。確定在jsPlumb中點擊了哪個標籤

僅僅改變jsPlumb圖形是不夠的,因爲存在由jsPlumb圖形表示的未解壓數據結構。使用jsPlumb.ready和jsPlumb.bind的代碼已經很好地實現並且工作正常。

var newConn = jsPlumb.connect({ source: from, target: to, 
    endpoint: epStyle, detachable: false, 
    anchor: "Continuous", connector: ["StateMachine", { curviness: 20}], 
    paintStyle: lineSt, hoverPaintStyle: lineHoverSt, 
    overlays: [ 
    ["Arrow", { width: 10, length: 10, foldback: 1, location: 0.25, 
    id: "arrow_" + from + to + 1}], 
    ["Arrow", { width: 10, length: 10, foldback: 1, location: 0.75, 
    id: "arrow_" + from + to + 2}], 
    ["Label", 
     { label: relation.name, id: "label_" + from + to + rel_id, cssClass: "edgeLabel"} 
     // Any additional property here? 
    ] 
    ] 
}); 

//Or add property here? 
newConn.type = SOME_EDGE_TYPE; 

jsPlumb.ready(function() { 
    jsPlumb.bind("click", function (c) { 
    jsPlumb.detach(c); 
    }); 
    jsPlumb.bind("beforeDetach", function (conn) { 
    return confirm(
     "Are you sure you want to disconnect [" 
     + conn.sourceId + "=>" + conn.targetId + "]?"); 
    }); 
}); 
+0

那麼你想在點擊標籤時獲得端點(邊緣)嗎? – MrNobody

+0

...和「邊緣類型」(如標記圖中所示) –

+0

如果jsPlumb.connect返回邊(連接)對象,它可能會好得多。然後可以像下面這樣引用端點和附加的邊界類型:var newConn = jsPlumb.connect(...); newConn.type(...) –

回答

0

可以綁定一個事件jsPlumbConnection創建一個新的連接時得到通知:

jsPlumb.bind("jsPlumbConnection", function(ci) { 
      console.log(ci.connection); 
      console.log(ci.sourceId+" is connected to "+ci.targetId); 
}); 

爲了操縱jsPlumb連接參考API Document

的CI(連接信息)對象由以下的數據:

  1. 連接 - 新建立的連接。
  2. 源 - 連接中的源元素
  3. sourceEndpoint - 連接中的源端點。
  4. sourceId - 源元素的ID。
  5. target - 連接中的目標元素。
  6. targetEndpoint - 連接中的目標端點。
  7. targetId - 目標元素的ID。
+0

是的,但根據問題,怎麼做從連接中獲得對** Label **的引用? –

相關問題