列表
階層
- 列表
建構子
建構式 (constructor)
- new
List (length: number, commaSeparator?: boolean): List -
建立一個新的 Sass 列表。
⚠️ 注意!
列表元素的初始值是未定義的。在存取這些元素或將列表傳回 Sass 之前,必須使用 setValue 設定這些元素。
範例
const list = new sass.types.List(3);
list.setValue(0, new sass.types.Number(10, "px"));
list.setValue(1, new sass.types.Number(15, "px"));
list.setValue(2, new sass.types.Number(32, "px"));
list; // 10px, 15px, 32px參數
-
length: number
列表中(初始未定義)元素的數量。
-
選用 (Optional)
commaSeparator: boolean如果為
true
,則列表以逗號分隔;否則,以空格分隔。預設值為true
。
回傳 List
-
方法
取得長度 (getLength)
getSeparator
getValue
- getValue(index: number): undefined | LegacyValue
-
傳回索引
index
位置的元素,如果該值尚未設定,則傳回undefined
。範例
// list is `10px, 15px, 32px`
list.getValue(0); // 10px
list.getValue(2); // 32px拋出例外
如果
index
小於 0 或大於等於此列表的元素數量,則拋出Error
例外。參數
-
index: number
此列表的索引 (從 0 開始)。
回傳 undefined | LegacyValue
-
setSeparator
設定值 (setValue)
- 設定值 (setValue)(索引 (index): 數字 (number), 值 (value): 舊版值 (LegacyValue)): 無 (void)
-
將位於
index
的元素設定為value
。範例
// list is `10px, 15px, 32px`
list.setValue(1, new sass.types.Number(18, "px"));
list; // 10px, 18px, 32px拋出例外
如果
index
小於 0 或大於等於此列表的元素數量,則拋出Error
例外。參數
-
index: number
此列表的索引 (從 0 開始)。
-
值 (value): 舊版值 (LegacyValue)
回傳 void
-
Sass 的列表類型。
⚠️ 注意!
這個列表類型的各個方法使用以 0 為起始的索引,即使在 Sass 中列表使用以 1 為起始的索引。這些方法也不支援使用負數從列表末端反向索引。