![](/img/trans.png)
[英]Kendo grid error : kendo.all.min.js:12 Uncaught TypeError: e.slice is not a function
[英]KENDO UI 'Uncaught TypeError: e.slice is not a function'
我有一件很奇怪的事情正在发生。 在我的视图中添加以下 2 个脚本时。 我得到了错误
'未捕获的类型错误:e.slice 不是函数'
关于ajax调用的成功块。
Html.AppendScriptParts(string.Format("~/Administration/Scripts/kendo/{0}/kendo.data.min.js", kendoVersion));
Html.AppendScriptParts(string.Format("~/Administration/Scripts/kendo/{0}/kendo.web.min.js", kendoVersion));
这是我从后端的回应。
{"ExtraData":null,"Data":[{"Id":3,"TotalLicense":0,"TotalAvailableLicense":0,"TotalSoldLicense":0,"TotalLicenseAssignedToCustomer":0,"ProductSKU":"SLN-PP-001","ProductName":"Prepaid code - Full Stream License BCM 30 days","LicenseNumber":"BCQH EKDJ LP8E","Runtime":null,"ActivationStart":"01/01/0001","ActivationEnd":"01/01/0001","OwnerName":"Suman Kumar","OwnerEmail":"contact@devodee.com","ShortDescription":null,"OrderNumber":7,"ProductSeName":"prepaid-code-full-stream-license-bcm-30-days","SearchProductSKU":null,"SearchProductName":null,"SearchLicenseNumber":null,"SearchOwnerName":null,"SearchOwnerEmail":null,"SearchOrderNumber":0,"ShowProductSKUFront":false,"ShowProductNameFront":false,"ShowLicenseNumberFront":false,"ShowRuntimeFront":false,"ShowActivationStartFront":false,"ShowActivationEndFront":false,"ShowOwnerNameFront":false,"ShowOwnerEmailFront":false,"ShowShortDescriptionFront":false,"ShowOrderNumberFront":false,"ShowProductSKUBack":false,"ShowProductNameBack":false,"ShowLicenseNumberBack":false,"ShowRuntimeBack":false,"ShowActivationStartBack":false,"ShowActivationEndBack":false,"ShowOwnerNameBack":false,"ShowOwnerEmailBack":false,"ShowShortDescriptionBack":false,"ShowOrderNumberBack":false,"CustomProperties":{}},{"Id":4,"TotalLicense":0,"TotalAvailableLicense":0,"TotalSoldLicense":0,"TotalLicenseAssignedToCustomer":0,"ProductSKU":"SLN-PP-001","ProductName":"Prepaid code - Full Stream License BCM 30 days","LicenseNumber":"DW4W BBAJ TFQX","Runtime":null,"ActivationStart":"01/01/0001","ActivationEnd":"01/01/0001","OwnerName":"Suman Kumar","OwnerEmail":"contact@devodee.com","ShortDescription":null,"OrderNumber":8,"ProductSeName":"prepaid-code-full-stream-license-bcm-30-days","SearchProductSKU":null,"SearchProductName":null,"SearchLicenseNumber":null,"SearchOwnerName":null,"SearchOwnerEmail":null,"SearchOrderNumber":0,"ShowProductSKUFront":false,"ShowProductNameFront":false,"ShowLicenseNumberFront":false,"ShowRuntimeFront":false,"ShowActivationStartFront":false,"ShowActivationEndFront":false,"ShowOwnerNameFront":false,"ShowOwnerEmailFront":false,"ShowShortDescriptionFront":false,"ShowOrderNumberFront":false,"ShowProductSKUBack":false,"ShowProductNameBack":false,"ShowLicenseNumberBack":false,"ShowRuntimeBack":false,"ShowActivationStartBack":false,"ShowActivationEndBack":false,"ShowOwnerNameBack":false,"ShowOwnerEmailBack":false,"ShowShortDescriptionBack":false,"ShowOrderNumberBack":false,"CustomProperties":{}}],"Errors":null,"Total":2}
当我删除下面的 JS 时,
//Html.AppendScriptParts(string.Format("~/Administration/Scripts/kendo/{0}/kendo.data.min.js", kendoVersion));
错误已清漆。 但是这两个 JS 都必须添加到视图中才能获得其他一些功能。
kendo.web.min.js:13 Uncaught TypeError: e.slice is not a function
at init.success (kendo.web.min.js:13)
at i (jquery-1.10.2.min.js:4)
at Object.n.success (kendo.data.min.js:11)
at c (jquery-1.10.2.min.js:4)
at Object.fireWith [as resolveWith] (jquery-1.10.2.min.js:4)
at k (jquery-1.10.2.min.js:6)
at XMLHttpRequest.r (jquery-1.10.2.min.js:6)
谁能详细说明这里出了什么问题,我错过了什么吗?
当我使用不带小部件的kendo.DataSource
从后端检索单个对象(序列化为 JSON)时,我也遇到了这个错误。 我的解决方法是添加一个假slice()
函数,该函数返回对象本身的克隆:
schema: {
data: (response: any) => {
// Augment returned data with a slice() method used internally by Kendo DataSource
// in the absence of "schema.model" to obtain a pristine copy of the object.
response.slice = () => JSON.parse(JSON.stringify(response));
return response;
}
}
清除控件时,我使用kendoAutoComplete
编辑器控件收到此错误。 第一次在控件中输入字符时不会发生这种情况,因为在输入至少两个字符之前它不会发出服务器请求。 该控件使用服务器过滤通过 JSON 请求检索数据。 问题是我正在服务器上测试 null 或空过滤器,在这种情况下返回了一个空的 JSON 对象。
修复是返回一个空的 JSON 数组。
在我的例子中,我在我的 Kendo ViewModel 的刷新函数中使用了一个异步查询,然后尝试在 ListView 之后立即将值传递给函数调用。 由于 AJAX 查询仍在运行,它在传递时为空。
UserProfileNotesViewModel.prototype.initialize = function () {
var _this = this;
if (!this.isInitialized) {
this.container = $("#user-profile-note-container");
this.addModal = $("#user-profile-entry-note-modal");
this.infoViewModel = new InfoViewModel(this);
this.refresh().then(function () { return _this.isInitialized = true; });
let datasource = this.infoViewModel.get("data");
$("#notes-listview").kendoListView({
dataSource: {
data: data,
pageSize: 21
},
schema: {
data: (response) => {
// Augment returned data with a slice() method used internally by Kendo DataSource
// in the absence of "schema.model" to obtain a pristine copy of the object.
response.slice = () => JSON.parse(JSON.stringify(response));
return response;
}
},
template: kendo.template($("#note-search-template").html()),
pageable: true
});
}
};
相反,我将 notes-listview 函数调用添加到 AJAX 查询末尾的 always 块中。 这导致数据在被请求时被填充。
UserProfileNotesViewModel.prototype.refresh = function () {
var _this = this;
kendo.ui.progress(this.container, true);
return $.ajax({
url: Ccf.Utility.serviceUrl + "User/GetUserNotes/" + _this.options.userId,
method: "GET",
contentType: "application/json; charset=UTF-8",
dataType: "json"
})
.done(function (data, textStatus, jqXHR) {
_this.infoViewModel.set("data", data);
})
.fail(function (data, textStatus, errorThrown) {
_this.infoViewModel.set("messages", Ccf.Utility.getAjaxMessages(data));
})
.always(function (data, textStatus, errorThrown) {
kendo.ui.progress(_this.container, false);
$("#notes-listview").kendoListView({
dataSource: {
data: data,
pageSize: 21
},
schema: {
data: (response) => {
// Augment returned data with a slice() method used internally by Kendo DataSource
// in the absence of "schema.model" to obtain a pristine copy of the object.
response.slice = () => JSON.parse(JSON.stringify(response));
return response;
}
},
template: kendo.template($("#note-search-template").html()),
pageable: true
});
if (!_this.isInitialized) {
kendo.bind(_this.container, _this.infoViewModel);
}
});
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.