JavaScript Blockly.FieldDropdown 参数

JavaScript Blockly.FieldDropdown parameters

我正在用 blockly 做一个项目,它是一个 javascript 库,我无法理解 [=22 的 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 {(!Array.|!Function)} 是什么意思

documentation has more information and examples, including the basic structure of the dropdown options and how to make a dynamic dropdown menu.

基本结构为:

Each dropdown menu is created with a list of menu options. Each option is made up of two strings. The first is the human-readable text to display. The second is a string constant which is used when saving the option to XML. This separation allows a dropdown menu's setting to be preserved between languages. For instance an English version of a block may define [['left', 'LEFT'], ['right', 'RIGHT']] while a German version of the same block would define [['links', 'LEFT'], ['rechts', 'RIGHT']].

对于动态菜单:

Instead of providing a static list of options, one can provide a function that returns a list of options when called. Every time the menu is opened, the function is called and the options are recalculated.

如果menuGenerator是一个数组,则使用它;如果它是一个函数,则在打开菜单时它是 运行。该函数不接受任何参数;它 returns 一个选项列表,结构如上所述。