0

我已经实现了一个上下文菜单处理程序,它向工作区添加了一个块。我正在尝试在调用上下文菜单的块和可能已经连接到它的任何块之间添加块( previousConnection )。我正在拍摄的内容以及我拥有的代码以及它的作用......

context menu option handler:
   var option =
   {
      text: "Comment",
      enabled: true,
      callback: function ()
      {
         var comment = workspace.newBlock('ta_comment');
         var block = Blockly.ContextMenu.currentBlock;

         block.previousConnection.connect(comment.nextConnection);

         comment.initSvg();
         comment.render();
      }
   }

   menuOptions.push(option);

之前 之后

4

1 回答 1

1
     //create comment block and get the block that summoned the context menu
     var comment = workspace.newBlock('ta_comment');
     var block = Blockly.ContextMenu.currentBlock;

     //connect up comment block
     comment.previousConnection.connect(block.previousConnection.targetConnection);
     comment.nextConnection.connect(block.previousConnection);

     //init
     comment.initSvg();

     //render updated workspace
     workspace.render();
于 2016-12-12T21:36:40.767 回答