我在Gojs中使用滚动表。 我为我的表设置了属性" editable:true" 。现在,假设我已经在一行的任何列中编辑了文本,那么如何获取整行或编辑文本的数据? 如果你知道的话请告诉我。
这是我的代码:
var nodeJson;
var $ = go.GraphObject.make;
var inputFieldTable = [
{ ID: "001", Name: "Input 1", Text: "Err1" },
{ ID: "002", Name: "Input 2", Text: "Err2" },
{ ID: "003", Name: "Input 3", Text: "Err3" },
{ ID: "004", Name: "Input 4", Text: "Err4" }
];
var outputFieldTable = [
{ ID: "101", Name: "Output 1", Text: "Integer" },
{ ID: "102", Name: "Output 2", Text: "Integer" },
{ ID: "103", Name: "Output 3", Text: "Integer" },
{ ID: "104", Name: "Output 4", Text: "String" },
{ ID: "105", Name: "Output 5", Text: "String" },
{ ID: "106", Name: "Output 6", Text: "Double" }
];
myDiagram =
$(go.Diagram, "myDiagramDiv",
{
initialContentAlignment: go.Spot.Center,
"undoManager.isEnabled": true,
allowMove: false,
allowDelete: true,
allowCopy: false,
allowDragOut: false,
allowDrop: false
});
myDiagram.nodeTemplate =
$(go.Node, "Vertical",
{
selectionObjectName: "SCROLLING",
resizable: false, resizeObjectName: "SCROLLING",
portSpreading: go.Node.SpreadingNone
},
new go.Binding("location").makeTwoWay(),
$(go.TextBlock,
{ font: "bold 14px sans-serif" },
new go.Binding("text", "key")),
$(go.Panel, "Auto",
$(go.Shape, { fill: "white" }),
$("ScrollingTable",
{ stretch: go.GraphObject.Fill },
new go.Binding("TABLE.itemArray", "items"),
new go.Binding("TABLE.column", "left", function (left) { return left ? 2 : 0; }),
new go.Binding("desiredSize", "size").makeTwoWay(),
{
name: "SCROLLING",
desiredSize: new go.Size(100, 100),
"TABLE.itemTemplate":
$(go.Panel, "TableRow",
{
defaultStretch: go.GraphObject.Horizontal,
fromSpot: go.Spot.LeftRightSides,
toSpot: go.Spot.LeftRightSides,
fromLinkable: true,
toLinkable: true,
},
new go.Binding("portId", "Name"),
$(go.TextBlock, { column: 1 }, new go.Binding("text", "Name")),
$(go.TextBlock, { column: 2 }, new go.Binding("text", "Text"), { editable: true })
),
"TABLE.defaultColumnSeparatorStroke": "gray",
"TABLE.defaultColumnSeparatorStrokeWidth": 0.5,
"TABLE.defaultRowSeparatorStroke": "gray",
"TABLE.defaultRowSeparatorStrokeWidth": 0.5,
"TABLE.defaultSeparatorPadding": new go.Margin(1, 3, 0, 3)
}
)
)
);
myDiagram.model = $(go.GraphLinksModel,
{
linkFromPortIdProperty: "fromPort",
linkToPortIdProperty: "toPort",
nodeDataArray: [
{
key: "Input", left: true, location: new go.Point(0, 0), size: new go.Size(170, 100),
items: inputFieldTable
},
{
key: "Output", location: new go.Point(300, 0), size: new go.Size(170, 100),
items: outputFieldTable, editable: true
}
]
});
//Function to handle editing of Scrolling Tables row data
myDiagram.addDiagramListener("TextEdited",
function (e) {
// alert("Text is changed.");
var part = e.subject.part;
if (part.data.key.toUpperCase() == "INPUT") {
myDiagram.rollbackTransaction();
return false;
}
else if (part.data.key.toUpperCase() == "OUTPUT") {
if ((part instanceof go.Node)) {
//NEED TO KNOW THE ENTIRE ROW DATA HERE
}
}
});
答案 0 :(得分:1)
您是否在询问如何从“TextEdited”收听者中获取商品数据?
e.subject
将是经过编辑的 TextBlock 。e.subject.panel
将包含 Panel ,这是 Panel.itemTemplate 中的“TableRow”。e.subject.panel.data
将是商品数据 - 即该行的数据。这适用于所有带有itemArrays的Panel - 而不仅仅是“ScrollingTable”。
TextBlock.editable TextBlock没有TwoWay Binding ,这有点奇怪,但它可以正常,具体取决于你在“TextEdited”监听器中的操作
答案 1 :(得分:0)
您必须通过调用以下
来获取模型中的所有值myDiagram.model.nodeDataArray
然后,您需要遍历对象以确定哪些值已更改。