How to add context menu items conditionally

I had a visual tree diagram and for tree node i need to display context items
and to display that menu item there some conditions if that condition fails i should not display that particular item.
below is the code

this.goMaker(go.TextBlock,

                {

                    font: "bold 14px Muli-Regular",

                    stroke: "#333d46",

                    margin: 10,

                    width: 120,

                    height: 45,

                    maxLines: 1,

                    overflow: go.TextBlock.OverflowEllipsis,

                    text: "alignment: Left",

                    alignment: go.Spot.Left,

                    verticalAlignment: go.Spot.Top

                },

                new go.Binding("text", "name"),

                { contextMenu: this.goMaker("ContextMenu", this.contextmenuitems) },

            );

for the contextmenuitems i will load items on condition. if i add
that i getting the below error

Cannot add a GraphObject that already belongs to another Panel to this Panel: Panel(Auto)#412, already contained by Adornment(), cannot be shared by this Panel: Adornment()

It is commonplace to add a Binding on the button’s “visible” property. There are many examples of this, including Basic GoJS Sample. Note how in that sample most of the "ContextMenuButton"s have such a binding:

      // To simplify this code we define a function for creating a context menu button:
      function makeButton(text, action, visiblePredicate) {
        return $("ContextMenuButton",
          $(go.TextBlock, text),
          { click: action },
          // don't bother with binding GraphObject.visible if there's no predicate
          visiblePredicate ? new go.Binding("visible", "", (o, e) => o.diagram ? visiblePredicate(o, e) : false).ofObject() : {});
      }

      // a context menu is an Adornment with a bunch of buttons in them
      var partContextMenu =
        $("ContextMenu",
          . . .

Example usage:

          makeButton("Cut",
            (e, obj) => e.diagram.commandHandler.cutSelection(),
            o => o.diagram.commandHandler.canCutSelection()),