> 

 > 

4. 以积木式编程制作网络应用程式
输入
输入

本文档提供有关输入验证的指南,并管理各种输入类型,例如颜色输入、按钮、复选框、文本区域、选项列表、文件输入和数字输入。

输入验证

验证布局中的输入

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_validateInputs\"/></xml>"}

这用于检查布局中的输入是否有效。

参数: 屏幕专案
输出: 布尔值 (True/False)
示例代码:

使用一个 if-else 条件检查输入。

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_validateInputs\"><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">validation</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">The text is valid.</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">validation</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">The text is not valid.</field></shadow></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>resultButton</variable><variable>validation</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.URL</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Show Result</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">validation</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">validation</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_validateInputs\"><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">validation</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">The text is valid.</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">validation</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">The text is not valid.</field></shadow></value></block></statement></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

当输入有效时,输出:

验证布局中的输入 - 输出 1

当输入无效时,输出:

验证布局中的输入 - 输出 2

生成颜色输入

创建颜色输入

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createColorInput\"/></xml>"}

这用于在输入中创建颜色。

参数: N/A
输出: 屏幕专案
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>colorInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">colorInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createColorInput\"/></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">colorInput</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}

输入:

创建颜色输入 - 输出 1

您可以修改内部的颜色:

创建颜色输入 - 颜色 2

按钮

生成按钮

“创建”按钮

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow></value></block></xml>"}

这用于创建新按钮。

参数: 显示字符串:String
输出: 按钮
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>btn1</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">btn1</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Button</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">btn1</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

“创建”按钮 - “输出”

控制点击

在控制上单击

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value></block></xml>"}

此块用于单击按钮时,它将执行一些操作。

参数: 屏幕项目
输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><statement name=\"HANDLER\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">text</field></block></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>button</variable><variable>text</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">button</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Button</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">text</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">Hello</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><statement name=\"HANDLER\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">text</field></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

当单击按钮时,它将显示变量文本。

输出:

单击控制时 - 输出 1

点击按钮后:

单击控制时 - 输出 2

“设置文本开启”按钮

按钮设置内容

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_Button_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow></value></block></xml>"}

此块用于在按钮内设置文本。

参数:

  • 屏幕项目(输入控件)
  • 显示设置:字符串

输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>button</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">button</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Button</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><statement name=\"HANDLER\"><block type=\"Control_Button_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">You clicked this button.</field></shadow></value></block></statement></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

在单击“按钮”之前,输出:

按钮设置内容 - 输出(点击前)

点击“按钮”后,输出:

按钮设置内容 - 输出(点击后)

复选框

生成复选框

“创建”复选框

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createCheckbox\"/></xml>"}

这用于创建新的复选框。

参数: N/A
输出: 复选框
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>createCheckBox</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createCheckBox</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createCheckbox\"/></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createCheckBox</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

创建复选框 - 输出 1

单击复选框后:

创建复选框 - 输出 2

复选框的默认设置

复选框勾选 false

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_Checkbox_setChecked\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkbox</field></block></value><value name=\"isChecked\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}

此块用于设置默认复选框是否勾选。

参数:

  • 屏幕项目(输入控件)
  • 显示设置:布尔值 (True/False [Default])

输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>checkBox</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">checkBox</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createCheckbox\"/></value><next><block type=\"Control_Checkbox_setChecked\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkBox</field></block></value><value name=\"isChecked\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">checkBox</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

当将 checkbox 设置为 false 时,输出:

复选框 check false - 输出 1

当将 checkbox 设置为 true 时,输出:

复选框 check false - 输出 2

选中 复选框是否被选中

复选框处于选中状态

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_Checkbox_isChecked\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkbox</field></block></value></block></xml>"}

此块用于检查复选框是否被点击。

参数: 屏幕项目(输入控件)
输出: 布尔值 (True/False)
示例代码:

您可以使用 while 循环结合 if-else 条件来显示结果。

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_Checkbox_isChecked\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkBox</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkChecked</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">It is clicked.</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkChecked</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">It isn't clicked.</field></shadow></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>checkBox</variable><variable>checkChecked</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">checkBox</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createCheckbox\"/></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">checkBox</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">checkChecked</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">checkChecked</field></block></value><next><block type=\"device_while\"><value name=\"COND\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><statement name=\"DO\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_Checkbox_isChecked\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkBox</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkChecked</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">It is clicked.</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkChecked</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">It isn't clicked.</field></shadow></value></block></statement><next><block type=\"Task_sleep\"><value name=\"ms\"><shadow type=\"math_number\"><field name=\"NUM\">500</field></shadow></value></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

注意:您必须使用 “pause ms” 在 while (true) 循环内阻塞。 否则,它将具有无限循环,并且此 Web 应用程序将崩溃。

如果未单击复选框,则输出:

复选框已选中 - 输出 1

单击复选框时,输出:

复选框被选中 - 输出 2

文本区域

生成文本区域

创建文本区域

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createTextArea\"/></xml>"}

这用于创建新的文本区域。

参数: 显示设置:字符串
输出: 屏幕项目
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>textArea</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">textArea</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextArea\"/></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">textArea</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

创建文本区域 - 输出 1

您可以在文本区域内键入内容:

创建文本区域 - 输出 2

输入类型正确的文本

创建类型为

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.Text</field></block></xml>"}

此块用于告诉用户输入正确的类型。

参数: 显示设置:文本(默认)/电子邮件/URL
输出: 屏幕项目
示例代码:

将类型设置为文本时,输出:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>createInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.Text</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createInput</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}

将类型设置为电子邮件时,输出:

创建类型为 - 输出 2 的文本输入

将类型设置为 URL 时,输出:

创建类型为 - 输出 3 的文本输入

输入控制验证

输入控制验证输入

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_ChangeableInputControl_validateInput\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></xml>"}

此模块用于检查输入类型是否正确。

参数: 屏幕项目(输入控件)
输出: 布尔值 (True/False)。
示例代码:

使用这些块来检查用户是否在打字。

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_ChangeableInputControl_validateInput\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkInput</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Typing something</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkInput</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Please input correct type</field></shadow></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable><variable>checkInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.Email</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">checkInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">checkInput</field></block></value><next><block type=\"device_while\"><value name=\"COND\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><statement name=\"DO\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_ChangeableInputControl_validateInput\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkInput</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Typing something</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkInput</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Please input correct type</field></shadow></value></block></statement><next><block type=\"Task_sleep\"><value name=\"ms\"><shadow type=\"math_number\"><field name=\"NUM\">500</field></shadow></value></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

输入控制验证输入 - 输出 1

输入一些不正确的格式后,输出:

输入控制验证输入 - 输出 2

输入控制限制

需要输入控制 false

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_ChangeableInputControl_setInputRequired\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"isRequired\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}

如果该值设置为 true,则此块会限制用户输入该值。

参数:

  • 屏幕项目(输入控件)
  • 显示设置:布尔值 (True/False [Default])

输出: 布尔值 (True/False)。
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.Email</field></block></value><next><block type=\"Control_ChangeableInputControl_setInputRequired\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"isRequired\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

当变量 requirement 设置为 false 时,输出:

需要输入控制 false - 输出 1

当变量 requirement 设置为 true 时,输出:

需要输入控制 false - 输出 2

更改输入时有事件

输入控制更改时

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_ChangeableInputControl_onInputChanged\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></xml>"}

此块用于当用户在文本框中键入内容后在键盘中单击回车键时,它将执行一些操作。

参数: 屏幕项目(输入控件)
输出: N/A
示例代码:

当用户在文本框中输入内容并单击回车键时,它将显示您键入的文本。

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_ChangeableInputControl_onInputChanged\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><statement name=\"HANDLER\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createOutput</field></block></value><value name=\"content\"><block type=\"Control_ChangeableInputControl_getInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable><variable>createOutput</variable><variable>youWrote</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.Text</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createOutput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"variables_set\"><field name=\"VAR\">youWrote</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">You wrote:</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">youWrote</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createOutput</field></block></value><next><block type=\"Control_ChangeableInputControl_onInputChanged\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><statement name=\"HANDLER\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createOutput</field></block></value><value name=\"content\"><block type=\"Control_ChangeableInputControl_getInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

当不输入任何内容时,输出:

输入控制更改时 - 输出 1

当输入内容并用户单击回车键时,输出:

输入控制更改时 - 输出 2

设置初始值

输入控制设定值

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_ChangeableInputControl_setInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"v\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow></value></block></xml>"}

此块用于设置变量中的某些文本以供显示。

参数:

  • 屏幕项目(输入控件)
  • 显示设置:字符串

输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextArea\"/></value><next><block type=\"Control_ChangeableInputControl_setInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"v\"><shadow type=\"text\"><field name=\"TEXT\">Here is setting value</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

输入控制设定值 - 输出

显示文本区域值

输入控件获取值

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_ChangeableInputControl_getInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></xml>"}

此块用于从文本区域获取值以进行显示。

参数: 屏幕项目(输入控件)
输出: 屏幕项目
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable><variable>valueInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextArea\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">valueInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.Text</field></block></value><next><block type=\"Control_ChangeableInputControl_setInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"v\"><shadow type=\"text\"><field name=\"TEXT\">Typing something~</field></shadow></value><next><block type=\"Control_ChangeableInputControl_setInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">valueInput</field></block></value><value name=\"v\"><block type=\"Control_ChangeableInputControl_getInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">valueInput</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

输入控件获取值 - 输出

将焦点设置在元素上

输入控制焦点

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_InputControl_focus\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></xml>"}

此块将焦点设置在文本区域。 如果它是聚焦的,您可以在文本区域中键入内容。

参数: 屏幕项目(输入控件)
输出: N/A
示例代码:

这里设置按钮来检查变量是否被聚焦。

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_InputControl_focus\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable><variable>createButton</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextArea\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">createButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Click me to see focus</field></shadow></value></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_InputControl_focus\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></statement><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

当它未聚焦时,输出:

输入控制焦点 - 输出 1

当单击按钮查看焦点时,输出:

输入控制焦点 - 输出 2

打字限制

输入控制使能 false

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_InputControl_setInputEnabled\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"isEnabled\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}

该块限制用户在文本区域中键入内容。

参数:

  • 屏幕项目(输入控件)
  • 显示设置:布尔值 (True/False [Default])

输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable><variable>disableButton</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextArea\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">disableButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Click me to see enable is true.</field></shadow></value></block></value><next><block type=\"Control_InputControl_setInputEnabled\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"isEnabled\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">disableButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_InputControl_setInputEnabled\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"isEnabled\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></statement><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">disableButton</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

当首先将启用设置设置为 true 时,输出:

输入控制使能 false - 输出 1

点击按钮后,它将阻止文本区域,不允许您输入,输出:

输入控制使能 false - 输出 2

选项列表

生成选项列表

创建选项列表

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}

此块用于使用数组设置新的选项列表。

参数: 显示设置:

  • 布尔值 (True/False [Default])
  • 数组

输出: 屏幕项目
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}

不带选项的输入:

创建选项列表 - 不带选项的输出

带有选项的输出:

创建选项列表 - 带有选项的输出

取消选择所有选项

选项列表 取消选择所有选项

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_deselectAll\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></xml>"}

这用于取消选择选项列表中的所有选项。

参数: 屏幕项目(选项列表)
输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>resultButton</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Show Result</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_OptionList_deselectAll\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

在单击“显示结果”按钮之前,输出:

选项列表取消全选所有选项 - 输出 1

单击按钮后,输出:

选项列表取消全选所有选项 - 输出 2

选择所有选项

选项列表 选择所有选项

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_selectAll\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></xml>"}

这用于取消选择选项列表中的所有选项。

参数: 屏幕项目(选项列表)
输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>resultButton</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Show Result</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_OptionList_selectAll\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

选项列表 选择所有选项 - 输出 1

点击“显示结果”按钮后:

选项列表 选择所有选项 - 输出 2

取消选择某些选项

选项列表取消选择选项数组

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_deselectOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></xml>"}

这用于取消选择相关选项。

参数:

  • 屏幕项目(选项列表)
  • 数组

输出: N/A

范例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>resultButton</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Show Result</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_OptionList_deselectOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"2\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

选项列表取消选择选项 a b c 的数组 - 输出 1

点击“显示结果”按钮后:

选项列表取消选择选项 a b c 的数组 - 输出 2

选择一些选项

选项列表 选择选项数组

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_selectOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"2\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value></block></value></block></xml>"}

这用于选择相关选项。

参数:

  • 屏幕项目(选项列表)
  • 数组

输出: N/A

范例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>resultButton</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Show Result</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_OptionList_selectOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"2\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

选项列表 选择选项 a b c 的数组 - 输出 1

点击“显示结果”按钮后:

选项列表 选择选项数组 a b c - 输出 2

获取选定的选项

选项列表 获取所选选项

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_getSelectedOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></xml>"}

这用于获取选定的选项。

参数: 屏幕项目(选项列表)
输出: N/A
示例代码:

使用 for 循环获取所有选定的选项。

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">options</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_OptionList_getSelectedOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></value></block></statement></block></next></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>resultButton</variable><variable>options</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Show Result</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">options</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_OptionList_getSelectedOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></value></block></statement></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

选择 b、c 并单击“显示结果”按钮时的输出:

选项列表获取所选选项 - 输出

更改选项列表大小

选项列表集大小

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}

这用于设置选项列表的显示大小。

参数:

  • 屏幕项目(选项列表)
  • 条件:数字(预设值:0)

输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"Control_OptionList_setSize\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"size\"><shadow type=\"math_number\"><field name=\"NUM\">2</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

选项列表集大小 - 输出

具有多项选择的下拉列表

选项列表允许多项选择

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_setMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}

这用于允许它是否可以选择多个选项。

参数:

  • 屏幕项目(选项列表)
  • 条件:布尔值 (True/False [Default])

输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"Control_OptionList_setMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

设置为 false 时的输出:

选项列表允许多选 - 输出 1

设置为 true 时的输出:

选项列表允许多选 - 输出 2

检查选项列表是否多个

选项列表是多个

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_isMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></xml>"}

它用于检查它是否是多个。

参数: 屏幕项目(选项列表)
输出: 布尔值 (True/False)
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>checkMultiple</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">checkMultiple</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">checkMultiple</field></block></value><next><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_OptionList_isMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkMultiple</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">It is multiple.</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkMultiple</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">It is not multiple.</field></shadow></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

当它设置为 false 时,输出:

选项列表是多个 - 输出 1

当它设置为 true 时,输出:

选项列表是多个 - 输出 2

在选项列表中设置多项选择

选项列表 设置选项数组

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_setOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></xml>"}

这用于设置选项列表中的选项。

参数: 屏幕项目(选项列表)
输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"Control_OptionList_setOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

选项列表 设置选项数组 - 输出

获取所有选项

选项列表获取选项

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_getOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></xml>"}

这用于获取选项列表中的所有选项。

参数: 屏幕项目(选项列表)
输出: 屏幕项目
示例代码:

使用 for 循环获取所有选项。

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>options</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">options</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_OptionList_getOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

输出:

选项列表 获取选项 - 输出

文件输入

生成文件输入

创建文件输入

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createFileInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"true\"></mutation><field name=\"fileTypeFilter\">FileInputTypeFilter.None</field><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value></block></xml>"}

此块允许您上传带有变量的文件。

参数: 显示设置:无(默认)/布尔(真/假[Default])
输出: 屏幕项目
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>createFileInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createFileInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createFileInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"true\"></mutation><field name=\"fileTypeFilter\">FileInputTypeFilter.None</field><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createFileInput</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}

您可以设置用户是否可以选择多个文件。

创建文件输入 - 输出 1

当未选择任何文件时,输出:

创建文件输入 - 输出 1

当将多个选择设置为 false 时,输出:

创建文件输入 - 输出 2

当将多个选择设置为 true 时,输出:

创建文件输入 - 输出 3

获取以前的文件

文件输入获取文件

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_FileInput_getFiles\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></xml>"}

此块从先前选定的文件中获取文件。

参数: 屏幕项目(输入控制:文件输入)
输出: 屏幕项目
示例代码:

为了检查这一点,它可以与文件和数组的块结合使用。 它设置了一个按钮来检查它是否可以获取文件。

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">gettingFile</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_FileInput_getFiles\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></value><next><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">result</field></block></value><value name=\"content\"><block type=\"File_FileContainer_getName\"><value name=\"this\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">gettingFile</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></value></block></value></block></next></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>fileInput</variable><variable>createButton</variable><variable>result</variable><variable>gettingFile</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">fileInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createFileInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"Control_FileInput_setMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Getting files</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">result</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">result</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">gettingFile</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_FileInput_getFiles\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></value><next><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">result</field></block></value><value name=\"content\"><block type=\"File_FileContainer_getName\"><value name=\"this\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">gettingFile</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></value></block></value></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

选择PNG文件并单击“获取文件”时,输出:

文件输入 get files - 输出 1

当获取文件名并单击“获取文件”时,输出:

文件输入 get files - 输出 2

当在文件内获取图像并单击“获取文件”时,输出:

文件输入 get files - 输出 3

当在文件内获取视频并单击“获取文件”时,输出:

文件输入 get files - 输出 5

当获取文件内的文本(接受的文件类型:txt)并单击“获取文件”时,输出:

文件输入 get files - 输出 6

文件格式限制

文件输入过滤器文件类型

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_FileInput_setFileTypeFilter\"><field name=\"filter\">FileInputTypeFilter.None</field><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></xml>"}

此块限制用户选择具有其文件类型的文件。

参数:

  • 屏幕项目(输入控制:文件输入)
  • 显示设置:无(默认)/图像/视频/音频

输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>fileInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">fileInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createFileInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"Control_FileInput_setFileTypeFilter\"><field name=\"filter\">FileInputTypeFilter.Audio</field><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

无限制选择文件后的输出:

文件输入过滤器文件类型 - 输出 1

选择仅允许图像输入的文件(接受的文件类型:JPEG、PNG 等)后的输出:

文件输入过滤器文件类型 - 输出 2

选择仅允许视频输入的文件(接受的文件类型:MP4、M4A 等)后的输出:

文件输入过滤器文件类型 - 输出 3

选择仅允许音频输入的文件(接受的文件类型:MP3、WAV 等)后的输出:

文件输入过滤器文件类型 - 输出 4

具有多项选择的文件输入

文件输入允许多选

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_FileInput_setMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}

此块用于设置用户是否可以选择一个或多个文件。

参数:

  • 屏幕项目(输入控制:文件输入)
  • 显示设置:布尔值 (True/False [Default])

输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>createFileInput</variable><variable>createButton</variable><variable>count</variable><variable>gettingFile</variable><variable>fileInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createFileInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createFileInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"true\"></mutation><field name=\"fileTypeFilter\">FileInputTypeFilter.None</field><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></value><next><block type=\"Control_FileInput_setMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createFileInput</field></block></value><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createFileInput</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Getting the total number of files</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">count</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">gettingFile</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_FileInput_getFiles\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createFileInput</field></block></value></block></value><next><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"content\"><block type=\"text_join\"><mutation items=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">There are </field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">gettingFile</field></block></value></block></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\"> file(s).</field></shadow></value></block></value></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

点击按钮后,它将显示文件总量的结果,当它设置为 false 时,输出:

文件输入允许多选 - 输出 1

当设置为 true 时,输出:

文件输入允许多选 - 输出 2

检查文件输入是否多个

文件输入是多个

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_FileInput_isMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></xml>"}

此块检查文件的数量是否仅为一个或多个。

参数: 屏幕项目(输入控制:文件输入)
输出: 屏幕项目
示例代码:

它将与不同的逻辑块相结合,例如 if-else 条件块。

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_FileInput_isMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"content\"><block type=\"text_join\"><mutation items=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">There are </field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">gettingFile</field></block></value></block></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\"> file(s).</field></shadow></value></block></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Only one file is selected.</field></shadow></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>fileInput</variable><variable>createButton</variable><variable>count</variable><variable>gettingFile</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">fileInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createFileInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><field name=\"fileTypeFilter\">FileInputTypeFilter.None</field><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Check multiple files</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">count</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">gettingFile</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_FileInput_getFiles\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></value><next><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_FileInput_isMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"content\"><block type=\"text_join\"><mutation items=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">There are </field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">gettingFile</field></block></value></block></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\"> file(s).</field></shadow></value></block></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Only one file is selected.</field></shadow></value></block></statement></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

当存在多个文件时,输出:

文件输入是多个 - 输出 1

当仅包含一个文件时,输出:

文件输入是多个 - 输出 2

数值输入

生成数值输入

创建数值输入

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createNumericInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></xml>"}

此模块用于创建数字 (1,2,3…) 输入。

参数: 显示设置:

  • 最小值:op(默认值:0)
  • 最大值:数字(默认值:0)
  • 步骤:数字(默认值:0)

输出: 屏幕项目
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>numInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">numInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createNumericInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"3\" _input_init=\"true\"></mutation><value name=\"min\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value><value name=\"max\"><shadow type=\"math_number\"><field name=\"NUM\">100</field></shadow></value><value name=\"step\"><shadow type=\"math_number\"><field name=\"NUM\">3</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">numInput</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}

输入:

创建数值输入 - 输出 1

您可以使用键入或滚动来输入值:

创建数值输入 - 输出 2

您可以设置最小值和最大值以及步长。 该步长表示如果将步长设置为 3,则只能输入 3 的倍数,例如 3、6、9。

创建数值输入 - 输出 3

数值输入中的步骤属性

数值输入设置步骤

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_NumericInput_setStep\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value><value name=\"step\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}

此模块用于设置数字输入的步长。

参数: 显示设置:数字(默认:0)
输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>numericInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">numericInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createNumericInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"Control_NumericInput_setStep\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value><value name=\"step\"><shadow type=\"math_number\"><field name=\"NUM\">2</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

当步长设置为 2 时,输出:

数字输入设置步骤 - 输出

数值输入中的最大值限制

数值输入集最大值

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_NumericInput_setMax\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value><value name=\"max\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}

此模块用于设置数值输入的最大值。

参数: 显示设置:数字(默认:0)
输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>numericInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">numericInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createNumericInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"Control_NumericInput_setMax\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value><value name=\"max\"><shadow type=\"math_number\"><field name=\"NUM\">5</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

当它设置为 5 时,它不能选择大于 5 的值,输出:

数字输入集 max - 输出

数值中的最小值限制

数值输入设置最小值

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_NumericInput_setMin\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value><value name=\"min\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}

此模块用于设置数值输入的最小值。

参数: 显示设置:数字(默认:0)
输出: N/A
示例代码:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>numericInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">numericInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createNumericInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"Control_NumericInput_setMin\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value><value name=\"min\"><shadow type=\"math_number\"><field name=\"NUM\">-1</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}

当它设置为 -1 时,它不能选择小于 -1 的值,输出:

数字输入设置最小值 - 输出

目录