KENDO UI“Uncaught TypeError:e.slice不是一个函数”

6

我遇到了一个非常奇怪的问题。当以下两个脚本添加到我的视图中时,我会收到以下错误:

'Uncaught TypeError: e.slice is not a function'

在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));

错误已消失。但是这两个 JavaScript 必须添加到视图中,以满足其他功能要求。
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)

错误::脚本行和代码

请问这里出了什么问题,我有些遗漏吗?


3
当您的小部件配置出现问题时,例如网格,Kendo会抛出这些类型的错误。通常是绑定到无法找到的函数。您需要在问题中包含网格的HTML和任何相关的JS。 - NigelK
可能是e.slice is not a function error in ASP.NET MVC with Kendo UI的重复问题。 - Roman Koliada
@RomanKoliada 不,你所提到的问题与我的不同,因为我的不是MVC版本。并且正如建议的那样,我正在将一个数组返回给网格而不是一个对象(请参见上面的后端响应)。 - SumanP89
@RomanKoliada 不,你所提到的问题与我的不同,因为我的不是MVC版本。并且正如建议的那样,我正在将一个数组返回给网格而不是一个对象(请参见上面的后端响应)。 - SumanP89
@NigelK 是的,所有必需的JS都已添加。但问题在于当我同时添加Kendo.data和Kendo.web JS时。只有添加Kendo.web JS时才有效。 - SumanP89
3个回答

4

当我在没有小部件的情况下使用 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;
                }
            }

我添加了我的网格数据源并使用databound绑定我的数据,但我的数据没有添加到combobox中。我很好奇为什么会这样。我的代码如下:dataBound: function(e){ var equipmentData = e.sender.dataSource.data(); equipmentData.slice =()=> JSON.parse(JSON.stringify(equipmentData));
$.each(equipmentData,function(index,selectedEquipmentData){
var dataItem = e.sender.dataSource.at(index); })},
- merve şahinoglu

2
当清除控件时,我在 kendoAutoComplete 编辑器控件中遇到了这个错误。当首次输入字符到控件中时,它不会发出服务器请求,因为至少有两个字符才会发出。该控件使用服务器过滤通过 JSON 请求检索数据。问题是我在服务器上测试空过滤器,并在该情况下返回一个空的 JSON 对象。
修复方法是返回一个空的 JSON 数组。

0
在我的情况下,我正在使用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);
                        }
                    });
            };

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接