內嵌與外部輸入來源
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
輸入內容可以內嵌或外部方式呈現。這項設定可控制值輸入的連接器是否要在方塊內 (內嵌) 或外側邊緣 (外部) 算繪,以及輸入內容是否要在相同或不同列中算繪。

區塊定義可以指定選用的布林值,控制輸入內容是否為內嵌。
JSON
{
// ...,
"inputsInline": true
}
JavaScript
init: function() {
// ...
this.setInputsInline(true);
}
如果這個布林值設為 true
(內嵌輸入):
- 值輸入的連接器會顯示在方塊內。
- 陳述式輸入內容會顯示在各自的列中。
- 虛擬、資料列結尾和值輸入內容都會顯示在同一列,但陳述式或資料列結尾輸入內容後方的任何輸入內容,都會顯示在新的一列。
設為「外部輸入」false
時:
- 值輸入的連接器會顯示在方塊的外側邊緣。
- 所有輸入內容都會顯示在各自的資料列中,但如果資料列結尾的輸入內容接在虛擬輸入內容後面,則會與虛擬輸入內容顯示在同一列。
如果難以想像,請在 Blockly 開發人員工具中建構方塊,並為 inputs
下拉式選單選擇不同設定 (automatic
、external
、inline
)。
如果未定義這個布林值,Blockly 會使用一些啟發式方法,猜測哪種模式最合適。假設 Blockly 會做出正確選擇,最好不要定義這個欄位,因為不同語言的翻譯可以自動採用不同模式。請參閱「插補權杖順序」一文中的 "set %1 to %2"
(外部輸入) 和 "put %2 in %1"
(內嵌輸入) 範例。
如果區塊可能會有數字等小型輸入內容,請使用內嵌輸入內容。
使用者可以透過內容選單切換這個選項。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[],[],null,["# Inline vs. external inputs\n\nInputs can be rendered **inline** or **externally**. This controls whether the\nconnectors for value inputs are rendered inside the block (inline) or on the\noutside edge (external), as well as whether inputs are rendered in the same or\ndifferent rows.\n\nThe block definition can specify an optional boolean controlling whether inputs\nare inline or not. \n\n### JSON\n\n {\n // ...,\n \"inputsInline\": true\n }\n\n### JavaScript\n\n init: function() {\n // ...\n this.setInputsInline(true);\n }\n\nWhen this boolean is set to `true` (inline inputs):\n\n- The connectors for value inputs are rendered inside the block.\n- Statement inputs are rendered on their own row.\n- Dummy, end-of-row, and value inputs are all rendered in the same row, except that any input following a statement or end-of-row input is rendered on a new row.\n\nWhen it is set to `false` (external inputs):\n\n- The connectors for value inputs are rendered on the outside edge of the block.\n- All inputs are rendered in their own row, except that an end-of-row input that follows a dummy input is rendered in the same row as the dummy input.\n\nIf you're having trouble visualizing this, construct blocks in the\n[Blockly Developer Tools](https://google.github.io/blockly-samples/examples/developer-tools/index.html) and choose different settings for the\n`inputs` dropdown (`automatic`, `external`, `inline`).\n\nIf this boolean is not defined then Blockly will use some heuristics to guess\nwhich mode is\nbest. Assuming Blockly makes the right choice, leaving this field undefined\nis preferable since different language translations can automatically have\ndifferent modes. See the example of `\"set %1 to %2\"` (external inputs) and\n`\"put %2 in %1\"` (inline inputs) in [Interpolation token\norder](/blockly/guides/create-custom-blocks/define/structure-json#interpolation_token_order).\n\nUse inline inputs when a block is likely to have small inputs such as numbers.\nThe user can toggle this option through the context menu."]]