You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GoJS页面流文档添加组模板至选择器及主区域问题求助

How to Add Group Templates to a GoJS Palette

Hey there, let's break down why your group template isn't showing up in the Palette and fix it!

The Root Issue

GoJS uses the isGroup: true flag to distinguish groups from regular nodes. When you added { category: "grp" } to palette.model.nodeDataArray, GoJS didn't recognize this as a group—it treated it like a standard node, so it pulled the default template from nodeTemplateMap instead of your intended group template.

Step-by-Step Fix

  1. Mark the Data as a Group
    Update your palette's node data array to include the isGroup: true flag for the group entry. This tells GoJS to use the corresponding group template instead of a node template:

    palette.model.nodeDataArray = [
      {}, // default node
      { category: "Source" },
      { category: "grp", isGroup: true } // Add the isGroup flag here
    ];
    
  2. Confirm Your Group Template is Properly Defined
    Make sure you've added the "grp" category template to your myDiagram.groupTemplateMap before sharing it with the Palette. Here's a quick example of how that might look:

    // Define your group template first
    myDiagram.groupTemplateMap.add("grp",
      $(go.Group, "Auto",
        $(go.Shape, "RoundedRectangle", { fill: "#cce6ff", stroke: "#336699" }),
        $(go.TextBlock, "New Group", { margin: 8, font: "bold 14px sans-serif" }),
        $(go.Placeholder, { padding: 10 }) // Needed to hold child nodes in the group
      )
    );
    
    // Initialize the Palette with shared template maps
    var palette = $(go.Palette, "myPaletteDiv", {
      nodeTemplateMap: myDiagram.nodeTemplateMap,
      groupTemplateMap: myDiagram.groupTemplateMap,
      autoScale: go.Diagram.Uniform
    });
    
  3. Double-Check Drag Behavior
    By default, GoJS Palettes allow dragging groups to the main Diagram, but if you've customized drag-related properties, ensure your group template has draggable: true (this is the default, but it's worth verifying if you've overridden any settings).

What This Does

  • With isGroup: true, the Palette now recognizes the entry as a group and uses the template from groupTemplateMap.
  • You'll still see your regular node templates (default and "Source") in the Palette, and dragging the group entry to the main Diagram will create a fully functional group that can hold child nodes.

内容的提问来源于stack exchange,提问作者art vanderlay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 22:52:27