Thank you. It works now, but there is a small defect. The objects in palette are reloading every time when I drop any of them to diagram. How to get rid if it?
Here’s the code:
// this DiagramEvent is raised when the user has drag-and-dropped something
// from another Diagram (a Palette in this case) into this Diagram
myDiagram.addDiagramListener("ExternalObjectsDropped", function (e) {
// stop any ongoing text editing
if (myDiagram.currentTool instanceof go.TextEditingTool) {
myDiagram.currentTool.acceptText(go.TextEditingTool.LostFocus);
}
// expand any "macros"
myDiagram.commandHandler.ungroupSelection();
// start editing the first node that was dropped after ungrouping
//var tb = myDiagram.selection.first().findObject('TEXT');
//if (tb) myDiagram.commandHandler.editTextBlock(tb);
jQuery.ajax({
type: "GET",
url: '/Home/GetRandomObjectProperties'
}).done(function (data) {
myDiagram.startTransaction("properties");
myPalette.model = new go.GraphLinksModel([
// a regular nodes
{ key: "B", text: "block B", color: "black" },
{ key: "C", text: "block C", color: "black" },
// a group nodes
{ key: "G", text: "Macro1", isGroup: true },
{ key: "D", text: "Macro2", isGroup: true },
{ category: "circle", key: "Gc", text: "A", color: "black", group: "G", loc: "0 0" },
{
category: "table", key: "Ga", group: "G", loc: "60 0",
properties: data.map(function (item) {
return { "property_name": item.Item1.toString(), "property_value": item.Item2.toString() };
})
},
{ category: "object1", key: "Gd", text: "AAAA", color: "black", group: "D", loc: "0 0" },
{
category: "table", key: "Ge", group: "D", loc: "60 0",
properties: data.map(function (item) {
return { "property_name": item.Item1.toString(), "property_value": item.Item2.toString() };
})
}
], []);
});
myDiagram.commitTransaction("properties");
});
myPalette.model = new go.GraphLinksModel([
// a regular nodes
{ key: "B", text: "block B", color: "black" },
{ key: "C", text: "block C", color: "black" },
// a group nodes
{ key: "G", text: "Macro1", isGroup: true },
{ key: "D", text: "Macro2", isGroup: true },
{ category: "circle", key: "Gc", text: "A", color: "black", group: "G", loc: "0 0" },
{
category: "table", key: "Ga", group: "G", loc: "60 0"
},
{ category: "object1", key: "Gd", text: "AAAA", color: "black", group: "D", loc: "0 0" },
{
category: "table", key: "Ge", group: "D", loc: "60 0"
}
], []);