在使用模板时,我们已经接触了一部分使用数据绑定的内容,但那只是最简单的应用,在官方文档中,数据绑定被细分为以下几种:
1.字符串和数字
var nodeDataArray = [
{
key: "Alpha", color: "lightblue" },
{
key: "Beta", color: "pink" }
];
diagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, "RoundedRectangle",
{
fill: "white" },
new go.Binding("fill", "color")), // shape.fill = data.color
$(go.TextBlock,
{
margin: 5 },
new go.Binding("text", "key")) // textblock.text = data.key
);
2.对象属性
diagram.nodeTemplate =
$(go.Node, "Auto",
new go.Binding("location", "loc"), // get the Node.location from the data.loc value
$(go.Shape, "RoundedRectangle",
{
fill: "white" },
new go.Binding("fill", "color")),
$(go.TextBlock,
{