2016-01-12 146 views
1

我有两个面板GoJs图,类似于http://gojs.net/latest/samples/flowchart.html。我将对象从左侧面板放到主图上。我如何获取/设置属性值ob对象像文本等?我被困在GoJS在ExternalObjectsDropped上丢弃对象值

myDiagram.addDiagramListener("ExternalObjectsDropped", 
    function (e) { 
     var part = e.subject; 
     console.log(e.subject); 
    }); 

控制台只显示非常复杂的对象结构,但我不知道在哪里找到我正在寻找的值。我的主要目标是调整放置对象的某些TextBlocks的大小。

回答

2

首先,了解源图中的模型数据将被复制到目标图的模型中。因此,源中的节点数据对象具有的可枚举属性应该出现在目标中创建的节点的节点数据对象上。

其次,您为什么要在复制的节点中“调整一些TextBlocks的大小”?如果他们的TextBlock.text属性是绑定到复制节点数据对象中的属性的数据,那么您真正想要做的是修改模型数据上的这些属性。所以,你的“ExternalObjectsDropped”听众可以这样做:

function(e) { 
    // according to the documentation e.subject in this case is 
    // the Diagram.selection, a Set of the copied Parts 
    e.subject.each(function(node) { 
     var model = e.diagram.model; 
     model.setDataProperty(node.data, "myProp1", ...); 
     model.setDataProperty(node.data, "myProp2", ...); 
    }); 
} 

或者,如果你真的想改变GraphObject.desiredSize的TextBlock S的任何其他属性,您可以通过给每个TextBlock中做明确一个GraphObject.name和调用Panel.findObject找到特定节点中的特定TextBlock。

页面http://gojs.net/latest/learn/graphObject.html提供了更多的讨论。

+0

在左侧面板中我想要有规则大小的节点。因为右边的节点会有两个可编辑的TextBlocks,并且里面会有很多文本,我想默认调整这些节点的大小。 – Ales

+2

听起来像你应该使用不同的模板。看看这个简介页面,它演示了每个图表如何使用不同的模板:http://gojs.net/latest/intro/palette.html –