如何从JointJS元素中的prop读取值?

时间:2019-02-15 09:57:38

标签: javascript jointjs

我尝试从JointJS元素中读取道具。我可以看到它被添加了,但是我不知道如何读取该值。

var uml = joint.shapes.uml;

var state = new uml.State({
  name: "some name",
  prop: { myId: "some id" },
  events: ["event1", "event2"],
  attrs: {
    ".uml-state-body": {
      fill: "rgba(48, 208, 198, 0.1)",
      stroke: "rgba(48, 208, 198, 0.5)",
      "stroke-width": 1.5
    },
    ".uml-state-separator": {
      stroke: "rgba(48, 208, 198, 0.4)"
    }
  }
});

this.graph.addCell(state);

这不起作用

this.paper.on("element:pointerup ", function(elementView) {
  var id = elementView.model.get("myId");
});

1 个答案:

答案 0 :(得分:1)

您真的很近...;)

具有实际代码的解决方案

我在吸气剂中使用CATCH来获得完整路径BEGIN TRY BEGIN TRANSACTION /* Do some operations */ /* Execute another SP that might have the following: BEGIN TRANSACTION -- Some other operations COMMIT */ COMMIT END TRY BEGIN CATCH DECLARE @v_ErrorMessage VARCHAR(MAX) = ERROR_MESSAGE() IF @@TRANCOUNT > 0 -- Only rollback if there is an active transaction ROLLBACK RAISERROR (@v_ErrorMessage, 16, 1) END CATCH

胜过您的工作:prop

https://codepen.io/Michal-Miky-Jankovsky/pen/PVXaZy

为什么?

构造函数中的所有对象键都是吸气剂的“属性”

更好的解决方案...

您可以直接在模型上设置“ myId”:

get("prop").myId

将可按预期使用吸气剂:

elementView.model.get("prop").myId