set 检查器类型用于从预定义选项中进行多项选择。set 检查器类型支持与 [下拉检查器类型](./type-dropdown.md) 相同的定义选项方法。
public function defineProperties()
{
return [
'units' => [
'title' => 'Select Muitple Units',
'type' => 'set',
'items' => [
'metric' => 'Metric',
'imperial' => 'Imperial'
]
]
];
}生成的输出是一个数组值,对应于所选选项,例如:
"units": ["metric", "imperial"]以下 配置值 是常用且受支持的。
| Property | Description |
|---|---|
| title | title for the property. |
| description | a brief description of the property, optional. |
| items | an array of available items as keys and values, optional if defining a get*PropertyName*Options method. |
| default | an array of selected items by default containing keys only. |
该 default 参数,如果指定, 应是一个列出默认选中的项键的数组。
public function defineProperties()
{
return [
'context' => [
'title' => 'Context',
'type' => 'set',
'items' => [
'create' => 'Create',
'update' => 'Update',
'preview' => 'Preview'
],
'default' => ['create', 'update']
]
];
}要动态指定 items,请创建一个名为 get*PropertyName*Options 的方法,该方法定义在模型中。
public function getContextOptions()
{
return ContextModel::pluck('name', 'code')->all();
}