2
我正在使用Kendo數據源綁定到網格。當用戶對行進行更改並調用save時,它會調用內部調用webapi以更新服務器的數據源Update函數。服務器返回相同的記錄格式,但有相同的數據項被其他用戶更新的機會,所以服務器將發送更新的記錄,並在數據源的成功調用中調用Kendo datasource在調用更新後重新填充
options.success(result)。但是網格和數據源都沒有獲取更新的數據。不知道我是否缺少一些東西。
this.remoteUsersDataSource = new kendo.data.DataSource({
transport: {
read: function (options) {
var contentType = "application/json; charset=utf-8";
$.ajax({
url: "/api/UserManagementApi",
dataType: "json",
type: "GET",
contentType: contentType,
data: { dataSourceRequest: JSON.stringify(options), searchPhrase: that.SearchPhrase },
cache: false,
success: function (result) {
options.success(result);
}
});
},
update: function (options) {
console.log("inside update");
console.log(options.data);
var url = that.Globals.updateUserLink;
var contentType = "application/json; charset=utf-8";
var dataType = "json";
that.Query({
type: "POST",
traditional: true,
url: url,
cache: false,
contentType: contentType,
dataType: dataType,
data:JSON.stringify(options.data)
}).done(function (result) {
console.log("success");
console.log(result);
options.success(result);
that.saveUserCallSuccess(result);
});
//that.saveUser(options);
}
},
page: this.Page,
pageSize: this.PageSize,
serverPaging: true,
serverSorting: true,
serverFiltering: true,
schema: {
data: function (response) {
console.log("inside data");
return response.Users;
},
model: {
id: "UserGuid",
pickStatusOption: function (e) {
that.MVVM = this;
that.pickStatusOption(e);
},
unLockUser: function (e) {
console.log(e);
e.preventDefault();
//e.data.IsUserPasswordLocked = false;
that.unlockUser(e);
}
},
total: function (response) {
return response.TotalCount;
}
},
change: function(e) {
console.log("change");
console.log(e);
},
error: function (e) {
console.log(e);
}
});
UPDATE * 想出初始負載運輸過程中的問題是在
schema: {
data: function (response) {
console.log("inside data");
return response.Users;
},
「讀」 返回 「響應」,其具有所謂的「用戶另一目的」。而當發生「更新」時,它會自行返回實際數據,並且不存在稱爲「用戶」的對象。所以我改變了我的「閱讀」爲 -
success: function (result) {
options.success(result.Users);
}
並從「模式」中刪除了「數據」部分。
我的WebAPI返航ID爲模型,並有一個匹配,以及與數據源dataitems。但是,我認爲問題是在一個不同的領域。我用我找到的解決方案更新了我的問題。謝謝 – Sai