跳转到主要内容

Multiselect(多选控件)

一组复选框。

multiselect_editor

注释

激活 multiselect 扩展后即可在灯箱中使用该控件

scheduler.plugins({
multiselect: true /*!*/
});

scheduler.locale.labels.section_userselect = "Participants";

scheduler.config.lightbox.sections = [
{ name:"description", height:50, map_to:"text", type:"textarea", focus:true },
{ name:"userselect", height:22, map_to:"user_id", type:"multiselect",
options: scheduler.serverList("users"), vertical:"false" },
{ name:"time", height:72, type:"time", map_to:"auto"}
];

灯箱中的多选控件

初始化

要将 Multiselect 控件添加到灯箱,请按以下步骤操作:

  1. 在页面上激活 'multiselect' 扩展:
scheduler.plugins({
multiselect: true
});
  1. 在灯箱配置中添加该 section:
scheduler.config.lightbox.sections = [
{ name:"description", ... },
{ name:"userselect", height:22, map_to:"user_id", type:"multiselect",
options: scheduler.serverList("user_id"), vertical:false },
{ name:"time", ...}
];
  1. 为该 section 设置标签:
scheduler.locale.labels.section_userselect = "Participants";

灯箱中的多选控件

属性

以下属性对 'multiselect' 控件来说最为重要且常被设置(完整列表请参见 这里):

使用数据填充控件

通常,要为多选按钮设置值,您应使用 options 参数:

scheduler.config.lightbox.sections = [
{ name:"userselect", type:"multiselect",
...
options:[
{ key: 1, label: 'George' },
{ key: 2, label: 'Nataly' },
{ key: 3, label: 'Diana' },
{ key: 4, label: 'Adam' }
]},
...
];

options 参数中的项必须具备两个必填属性:

  • key - 该选项的 id
  • label - 该选项的标签

从服务器填充复选框

要从服务器获取复选框的值,您需要使用 serverList 方法:

scheduler.config.lightbox.sections = [
{name:"description", ...},
{ name:"userselect", height:22, map_to:"user_id", type:"multiselect",
options: scheduler.serverList("users"), vertical:"false" },
{name:"time", ...}
];

scheduler.load("api/data");

其中 api/data 是一个 服务器端脚本,用于检索加载到调度程序的事件,以及一组多选按钮值,如下所示 Examples of Data Formats

//response
{
"data":[
{
"id":"1",
"start_date":"2019-03-02 00:00:00",
"end_date":"2019-03-04 00:00:00",
"text":"dblclick me!",
"user_id":"1,2"
},
{
"id":"2",
"start_date":"2019-03-09 00:00:00",
"end_date":"2019-03-11 00:00:00",
"text":"and me!",
"user_id":"2,3"
}
],
"collections": {
"users":[
{"value":"1","label":"Lisa"},
{"value":"2","label":"Bob"},
{"value":"3","label":"Mike"}
]
}
}
注释

注意,您可以使用 updateCollection 方法来更新检索选项列表

const oldOptions = scheduler.serverList("users").slice();
scheduler.updateCollection("users", [
{"value":"4","label":"John"},
{"value":"5","label":"Paul"},
{"value":"6","label":"Ringo"},
{"value":"7","label":"George"}
]);

动态加载

在静态模式下,所有事件参数选项都作为数据库中的单独字段存储,之后可以使用该字段来构建自己的逻辑。 它提供了更多的可能性,但需要为加载所有选项进行更多查询。

在动态模式下,不会存储额外的内容。选项按需加载。这减少了查询数量,但禁止构建任何逻辑。

在服务器端,代码应与以下类似

要启用动态模式,除了 options 外,还应使用 script_url 属性:

scheduler.config.lightbox.sections = [
{name:"userselect", height:22, map_to:"user_id", type:"multiselect",
options: scheduler.serverList("user_id"),
script_url:'api/options'},
...
];

其中 api/options 返回以下 JSON:

[                          
{"value":"1","label":"Lisa"},
{"value":"2","label":"Bob"},
{"value":"3","label":"Mike"}
]
Need help?
Got a question about the documentation? Reach out to our technical support team for help and guidance. For custom component solutions, visit the Services page.