我使用kendo UI来构建一个网格,但是我正在警告这个错误,它似乎是一个建筑错误,但我不知道什么是错误或丢失。
我在另一个论坛上看到,模型已经解决,但它对我没用。
function build_grid(result, id)
{
var gridData = {
DataColumn1: result.categories,
DataColumn2: result.datasource[0].data.map(function (a) { return a.value; }),
DataColumn3: result.datasource[1].data.map(function (a) { return a.value; }),
DataColumn4: result.datasource[1].data.map(function (a) { return a.percentage; }),
DataColumn5: result.datasource[2].data.map(function (a) { return a.value; }),
DataColumn6: result.datasource[2].data.map(function (a) { return a.percentage; })
};
var categories = [];
categories.push({ format:"n0" , field: "DataColumn1", title: "Column 1", width: "60px" });
categories.push({ format:"n0" , field: "DataColumn2", title: "Column 2", width: "100px" });
categories.push({ format:"n0" , field: "DataColumn3", title: "Column 3", width: "100px" });
categories.push({ format:"p2" , field: "DataColumn4", title: "Column 4", width: "100px" });
categories.push({ format:"n0" , field: "DataColumn5", title: "Column 5", width: "160px" });
categories.push({ format:"p2" , field: "DataColumn6", title: "Column 6", width: "160px" });
$(id + "Grid").kendoGrid({
columns: categories,
dataSource: {
data: gridData,
model: {
fields: {
DataColumn1: { type: "string" },
DataColumn2: { type: "number" },
DataColumn3: { type: "number" },
DataColumn4: { type: "number" },
DataColumn5: { type: "number" },
DataColumn6: { type: "number" }
}
}
},
height: 550,
groupable: true,
sortable: true,
});
}
Erro消息:
Uncaught TypeError: e.slice is not a function
at init.success (kendo.all.min.js:11)
at Object.success (kendo.all.min.js:11)
at init.read (kendo.all.min.js:11)
at kendo.all.min.js:11
at init._queueRequest (kendo.all.min.js:11)
at init.read (kendo.all.min.js:11)
at init.query (kendo.all.min.js:11)
at init._query (kendo.all.min.js:11)
at init.fetch (kendo.all.min.js:11)
at new init (kendo.all.min.js:30)
解决了,我将gridData变量更改为注释中提到的数组:
var gridData = [];
for (var i = 0 ; i < result.categories.length ; i++) {
gridData.push({
DataColumn1: result.categories[i],
DataColumn2: result.datasource[1].data[i].value,
DataColumn3: result.datasource[1].data[i].percentage,
DataColumn4: result.datasource[2].data[i].value,
DataColumn5: result.datasource[0].data[i].value,
DataColumn6: result.datasource[2].data[i].percentage
});
}
解决之后,我找到了另一个带有我的列格式的错误,正确的格式化方式是&#34; {0:n0}&#34;和&#34; {0:p2}&#34; ,不是&#34; n0&#34;或&#34; p2&#34;就像我以前用过的那样。