api.on()
描述
允许将处理函数绑定到内部事件
用法
api.on(
event: string,
handler: function,
config?: { tag?: number | string }
): void;
参数
event- (必填)要触发的事件handler- (必填)要绑定的处理函数(处理函数的参数取决于所触发的事件)config- (可选)包含处理函数额外设置的对象:tag- (可选)用于标识处理函数的标签,以便之后通过api.detach()方法将其移除
信息
Booking 内部事件的完整列表可在此处查看。
如果您只想监听操作而不修改它们,请使用 api.on() 方法。若要对操作进行修改,请使用 api.intercept() 方法。
示例
// 创建 Booking
const widget = new booking.Booking("#root", {
data,
// 其他配置参数
});
// 输出所选时间段的 id 和时间
widget.api.on("select-slot", (obj) => {
console.log("The selected slot", obj.id, "and time", obj.time);
});