如何在选中之前发出警报 - 取消选中一个kendo复选框

时间:2018-04-20 04:17:40

标签: javascript angularjs checkbox kendo-ui treeview

因此,如果用户想要选中一个复选框,如果他/她有权勾选,则会提示对话框。因此,当他没有权利时,国家将保持不变。

我正在使用带剑道树视图的angularjs。

 [[6,7,9,15,21,30],[2,4,7,9,13,24],[3,9,18,25,34,49],[7,13,17,21,25,28]]

}

enter image description here

1 个答案:

答案 0 :(得分:1)

Kendo UI的事件有时候设计得非常糟糕。示例herecheck事件被阻止,但它仍然执行更改,default JS behaviour中没有发生。您可以做的是对更改进行回滚

if (!window.confirm("Do you have the rights to change this?")) {
    window.setTimeout(function (node) {
        this.expand(node); // expand() creates the child list if not created yet
        $(node).find('input[type="checkbox"]').prop("checked", null);
    }.bind(this, e.node));
}

Demo

IKR很难看,但我无法想出更好的方法。好的一点是,复选框用户的点击,不是一个真正的复选框,它是一个span以某种方式在内部改变一个真正的隐藏复选框的状态,你check 3}}也许在他们的论坛中有人可以帮助提供更好的解决方案,但我对此并不确定。

<强>更新

实际上,代码段中存在逻辑错误。 check: function(e) { let dataItem = this.dataItem(e.node); if (!window.confirm("Do you have the rights to change this?")) { window.setTimeout(function (node, currentState) { this.expand(node); // Expand created the child list if not created yet $(node).find('input[type="checkbox"]').prop("checked", (currentState ? "checked" : null)); this.dataItem(node).set("checked", currentState); }.bind(this, e.node, !dataItem.checked)); } } 事件应为:

checked

can't prevent it's default click behaviour!

您报告的错误正在发生,因为它只更改了元素状态而不是DataItem的Logs属性,因此内部窗口小部件表现得很糟糕。此外,还有另一个错误,取消操作只是将复选框更改为未选中状态,这是错误的,因为用户可能 cenceling 选中复选框,因此必须保持状态检查。