我正在使用打字稿和淘汰赛。在我的示例中,我可以使用 kendo 自定义编辑器(例如淡入淡出或轮播)创建磁贴并设置事务。根据为图块设置的计时器,将显示数据。但是,当我导航到其他选项卡时,计时器事件会尝试查找不再可用的磁贴数据,从而引发错误。我想确保在导航到其他选项卡时,必须销毁或取消绑定所有具有事务事件的图块。我试过使用 ko.utils.domNodeDisposal.addDisposeCallback(element, function () 但它永远不会被调用。
init: (element: any, valueAccessor: any, allBindings: any, viewModel: any, bindingContext: any): void => {
tileState.editableTileInit(element, valueAccessor, viewModel);
ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
console.log("I have been called");
});
},
update: (element: any, valueAccessor: any, allBindings: any, viewModel: any, bindingContext: any): void => {
tileState.editableTileUpdate(element, valueAccessor, viewModel);
}
init 方法将创建瓷砖
if (viewModel.editMode() === true) LiveTiles.setupClickHandler(element, viewModel, true);
var sub = viewModel.editMode.subscribe(x => LiveTiles.setupClickHandler(element, viewModel, x));
ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
sub.dispose();
TileEditor.destroyEditor(element, viewModel);
LiveTiles.destroyTile(element, viewModel);
});
如果用户在运行时更新图块,update 方法将更新图块。
TileEditor.destroyEditor(element, viewModel);
LiveTiles.createTile(element, viewModel);
if (LiveTiles.shouldRecreateClickHandler(viewModel) === true) {
LiveTiles.setupClickHandler(element, viewModel, viewModel.editMode());
}