api.detach()
描述
用于移除/解绑动作处理器
用法
api.detach(tag: number | string ): void;
参数
tag- 动作标签的名称
示例
在下面的示例中,我们向 api.on() 处理器添加一个包含 tag 属性的对象,然后使用 api.detach() 方法停止记录 open-filter 动作。
// 创建 Pivot
const table = new pivot.Pivot("#root", {
fields,
data: dataset,
config: {
rows: ["studio", "genre"],
values: [
{
field: "title",
method: "count"
},
{
field: "score",
method: "max"
}
]
}
});
// 添加处理器
if (table.api) {
table.api.on(
"open-filter",
({ area }) => {
console.log("Opened: " + area);
},
{ tag: "track" }
);
}
// 解绑处理器
function stop() {
table.api.detach("track");
}
const button = document.createElement("button");
button.addEventListener("click", stop);
button.textContent = "Stop logging";
document.body.appendChild(button);