Hide TreeExpanderButton

If there is no child node under the node, the folding button hides or cancels the display button

Code:

this.go_ini = function () {
    var goi = go.GraphObject.make;
    var model = goi(go.TreeModel);
    var myDiagram =
        goi(go.Diagram, "myDiagramDiv",
     {
             initialAutoScale: go.Diagram.UniformToFill,
             layout: goi(go.TreeLayout, { nodeSpacing: 5, layerSpacing: 30 })
     });
    myDiagram.nodeTemplate =
    goi(go.Node, "Horizontal",
      {
          selectionObjectName: "PANEL",
          isTreeExpanded: false,
          isTreeLeaf: false
      },
    goi(go.Panel, "Auto",
    goi(go.Shape, { fill: "#091A22", stroke: null }),
       goi(go.TextBlock,
         {
             font: "bold 12px Helvetica, bold Arial, sans-serif",
             stroke: "white", margin: 3
         },
         new go.Binding("text", "name"))
     ),
     goi("TreeExpanderButton",
       {
           name: 'TREEBUTTON',
           width: 20, height: 20,
           alignment: go.Spot.TopRight,
           alignmentFocus: go.Spot.Center,
           click: function (e, obj) {
               var node = obj.part;
               if (node === null) return;
               e.handled = true;
               self.BOMexpandNode(node);
           }
       }
         )
     ); 

    myDiagram.linkTemplate =
               goi(go.Link,
                 { selectable: false },
                  goi(go.Shape));
    $.ajax({
        url: openinfo.root + "workspace/getclassattr",
        type: "POST",
        data: { class_id: "0005", data_id: "007CB2B5-C1A3-4284-B998-F3F0B5D477C0" },
        dataType: "json",
        beforeSend: function () {
   
        },
        complete: function () {
          
        },
        success: function (ret) {
            if (ret.code == "00000") {
                var itemCode = ret.data.ObjName.split('-')[0];
                var BOMname="设计BOM";
                myDiagram.model = new go.TreeModel([
                 { key: ret.data.ObjID, name: ret.data.ObjName,itemCode:itemCode, clsId: "0005", dataId:                ret.data.ObjID ,BOMname:BOMname,everExpanded: false}
                ]);

        }  else {
                var d = dialog({
                    title: '<i class="ace-icon fa fa-info-circle"></i> ' + '提示',
                    content: ret.msg
                });
                d.show();
                self.options.onError(ret);
            }
        },
        error: function () {
        }
    });
     this.myDiagram = myDiagram;
}

this.BOMexpandNode = function (node) {
    var diagram = node.diagram;
    diagram.startTransaction("CollapseExpandTree");
    // this behavior is specific to this incrementalTree sample:
    var data = node.data;
    if (!data.everExpanded) {
        diagram.model.setDataProperty(data, "everExpanded", true);
      
            self.ItemcreateSubTree(data, node);
     
    }
    // this behavior is generic for most expand/collapse tree buttons:
    if (node.isTreeExpanded) {
        diagram.commandHandler.collapseTree(node);
    } else {
        diagram.commandHandler.expandTree(node);
    }
    diagram.commitTransaction("CollapseExpandTree");
    self.myDiagram.zoomToFit();
}


this.ItemcreateSubTree = function (parentdata, nodes) {
    var model = self.myDiagram.model;
    var parent = self.myDiagram.findNodeForData(parentdata);
    $.ajax({
        url: openinfo.root + "data/GetBomGetList",
        type: "POST",
        data: { Bomitemcode: nodes.data.itemCode, BomType: nodes.data.BOMname },
        dataType: "json",
        success: function (ret) {
            if (ret.code == "00000") {
                console.log(ret.data)
                var retdata = ret.data;
                for (var i = 0; i < retdata.length; i++) {
                    var childdata = {
                        key: retdata[i].ItemCode,
                        parent: parentdata.key,
                        name: retdata[i].ItemCode+"-"+retdata[i].ItemName,
                        itemCode: retdata[i].ItemCode,
                        dataId: retdata[i].ID,
                        BOMname: "设计BOM",
           
                    };
                    // add to model.nodeDataArray and create a Node
                    model.addNodeData(childdata);
                    // position the new child node close to the parent
                    var child = self.myDiagram.findNodeForData(childdata);
                    child.location = parent.location;
                   }
                
                } else {
                var d = dialog({
                    title: '<i class="ace-icon fa fa-info-circle"></i> ' + '提示',
                    content: ret.msg
                });
                d.show();
                self.options.onError(ret);
            }
        },
        error: function () {
        }
    });
}

The complete definition of “TreeExpanderButton” is provided in https://gojs.net/latest/extensions/Buttons.js.

There you can see how there is a Binding of button.visible to Node.isTreeLeaf. If your goal is for the button not to become invisible when there are no tree children for a node, I suggest that you remove that Binding in your own copy of that “TreeExpanderButton” definition.

If that is not what you want, please explain, because your question was not clear.