题外话:自从可以科学上网后,翻看blockly文档那些就简单舒服多了~~
翻看了很久blockly文档,发现很少有关于ContextMenu的一些内容,经过一翻的搜索,终于找到解决的方法。
要自定义块右键的菜单(customContextMenu),需要在块定义的时候也定义这个customContextMenu。
直接上代码:
Blockly.Blocks['string_length'] = {
init:function() {
this.appendValueInput('VALUE')
.setCheck('String')
.appendField('length of');
this.setOutput(true, 'Number');
this.setColour(160);
this.setTooltip('Returns number of letters in the provided text.');
this.setHelpUrl('http://www.w3schools.com/jsref/jsref_length_string.asp');
// console.log(this)
},
customContextMenu:function(options) {
varoption= {
enabled:true,
text:"Custom option",
callback:function() {
}.bind(this)
};
options.push(option);
}
};
其实就是自定块的时候完成右键菜单的设置就ok了。
这些代码都必须