주요 콘텐츠로 건너뛰기

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);