我正在用javascript库布洛克做一个项目,我不知道Blockly.FieldDropdown函数的menuGenerator变量接受什么类型的参数。在这里,您可以看到一些感兴趣的代码:
/**
* Class for an editable dropdown field.
* @param {(!Array.<!Array>|!Function)} menuGenerator An array of options
* for a dropdown list, or a function which generates these options.
* @param {Function=} opt_validator A function that is executed when a new
* option is selected, with the newly selected value as i ts sole
argument.
* If it returns a value, that value (which must be one of the options)
will
* become selected in place of the newly selected option, unless the
return
* value is null, in which case the change is aborted.
* @extends {Blockly.Field}
* @constructor
*/
Blockly.FieldDropdown = function(menuGenerator, opt_validator) {我不明白@param {(!数组)!函数)}是什么意思。
发布于 2018-05-17 20:53:06
文档有更多的信息和示例,包括下拉选项的基本结构和如何生成动态下拉菜单。
基本结构是:
每个下拉菜单都有一个菜单选项列表。每个选项由两个字符串组成。第一种是人类可读文本的显示.第二个是字符串常量,它在将选项保存到XML时使用。这种分离允许在语言之间保留下拉菜单的设置。例如,一个块的英文版本可以定义
[['left', 'LEFT'], ['right', 'RIGHT']],而同一块的德语版本可以定义[['links', 'LEFT'], ['rechts', 'RIGHT']]。
对于动态菜单:
与其提供静态选项列表,还可以提供一个函数,在调用时返回选项列表。每次打开菜单时,都会调用该函数并重新计算选项。
如果menuGenerator是一个数组,则使用它;如果它是一个函数,则在打开菜单时运行。该函数不接受任何参数;它返回一个选项列表,结构如下所示。
https://stackoverflow.com/questions/50080076
复制相似问题