gpt4 book ai didi

javascript - 剑道数据源 : how cancel an update request

转载 作者:数据小太阳 更新时间:2023-10-29 04:42:27 24 4
gpt4 key购买 nike

我有一个剑道 UI 网格和一个数据源。当我调用 Update 方法时,我测试了一个变量,如果条件为假,我不想发送请求。

目前我有:

 $scope.MySource = new kendo.data.DataSource({
update: {
url: function (lista) {
if (testVariable== true) {
testVariable= false;
return "api/Liste/PutLista/" + lista.Id
}
else {
$scope.MySource.cancelChanges();
}
},
type: "PUT",
dataType: "json",
beforeSend: function (req) {
var auth = $window.sessionStorage.token;
req.setRequestHeader('Authorization', 'Bearer ' + auth);
}

如果 testVariable 为 false 我取消更新但我仍然看到一个 ajax 请求

http://localhost:61927/index.html with PUT method.

如果 testVariable 为 false,我如何阻止请求?

最佳答案

点击更新就可以拦截了。在您的剑道网格中,使用保存事件。每次您按下更新时都会调用此事件。

save: function (e) {
if (testVariable === false) {
e.preventDefault(); //prevent default action that kendo does
$scope.MySource.cancelChanges();
}
}

如果变量为 false,那么您将阻止默认操作并执行任何您想做的事情(例如取消更改)。如果为真,它只会采取默认操作并保存您的行。

只需确保变量 testVariable 在此事件中是可访问的(全局变量,或您可以在此事件中设置的局部变量)。

关于javascript - 剑道数据源 : how cancel an update request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24127585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com