kendo UI 如何将 xml 数据源绑定到 KendoGrid
kendo UI how to bind xml datasource to KendoGrid
我正在尝试将 XML 数据源绑定到 Kendo 网格。但是网格没有显示任何数据。
下面是代码
var dataSource = new kendo.data.DataSource({
data: '<books><book id="1"><title>Secrets of the JavaScript Ninja</title></book></books>',
schema: {
// specify the the schema is XML
type: "xml",
// the XML element which represents a single data record
data: "/books/book",
// define the model - the object which will represent a single data record
model: {
// configure the fields of the object
fields: {
// the "title" field is mapped to the text of the "title" XML element
title: "title/text()"
}
},
schema: {
model: {
fields: {
Title: { editable: false, nullable: true }
}
}
}
}
});
// alert(errorDataSource.read());
var pc = $("#gridError").kendoGrid({
//excel: { fileName: "Client Orders.xlsx", filterable: true },
dataSource: dataSource,
scrollable: true,
pageable: true,
navigatable: true,
columns: [
{ command: "destroy", width: 100 },
{
title: "Error Message",
//lock: true,
columns: [
{ field: "Title", title: "Error", width: 600, headerAttributes: { class: "k-header-wrap" } }
],
}
]
});
你能帮忙吗。
理想情况下,我现在想显示基于 e.XMLHttpRequest.responseText;
的错误消息
有什么简单的方法可以将其绑定到 Kendo-Grid 吗?
谢谢。
请尝试使用以下代码片段。字段名称 'title' 区分大小写。
<head>
<title></title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2015.2.902/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2015.2.902/styles/kendo.material.min.css" />
<script src="https://kendo.cdn.telerik.com/2015.2.902/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2015.2.902/js/kendo.all.min.js"></script>
</head>
<body>
<div id="gridError"></div>
<script>
var dataSource = new kendo.data.DataSource({
data: '<books><book id="1"><title>Secrets of the JavaScript Ninja</title></book></books>',
schema: {
// specify the the schema is XML
type: "xml",
// the XML element which represents a single data record
data: "/books/book",
// define the model - the object which will represent a single data record
model: {
// configure the fields of the object
fields: {
// the "title" field is mapped to the text of the "title" XML element
title: "title/text()"
}
},
schema: {
model: {
fields: {
title: { editable: false, nullable: true }
}
}
}
}
});
var pc = $("#gridError").kendoGrid({
//excel: { fileName: "Client Orders.xlsx", filterable: true },
dataSource: dataSource,
scrollable: true,
pageable: true,
navigatable: true,
columns: [
{ command: "destroy", width: 100 },
{
title: "Error Message",
//lock: true,
columns: [
{ field: "title", title: "Error", width: 600 }
],
}
]
});
</script>
</body>
如有任何疑问,请告诉我。
我正在尝试将 XML 数据源绑定到 Kendo 网格。但是网格没有显示任何数据。
下面是代码
var dataSource = new kendo.data.DataSource({
data: '<books><book id="1"><title>Secrets of the JavaScript Ninja</title></book></books>',
schema: {
// specify the the schema is XML
type: "xml",
// the XML element which represents a single data record
data: "/books/book",
// define the model - the object which will represent a single data record
model: {
// configure the fields of the object
fields: {
// the "title" field is mapped to the text of the "title" XML element
title: "title/text()"
}
},
schema: {
model: {
fields: {
Title: { editable: false, nullable: true }
}
}
}
}
});
// alert(errorDataSource.read());
var pc = $("#gridError").kendoGrid({
//excel: { fileName: "Client Orders.xlsx", filterable: true },
dataSource: dataSource,
scrollable: true,
pageable: true,
navigatable: true,
columns: [
{ command: "destroy", width: 100 },
{
title: "Error Message",
//lock: true,
columns: [
{ field: "Title", title: "Error", width: 600, headerAttributes: { class: "k-header-wrap" } }
],
}
]
});
你能帮忙吗。
理想情况下,我现在想显示基于 e.XMLHttpRequest.responseText;
的错误消息有什么简单的方法可以将其绑定到 Kendo-Grid 吗?
谢谢。
请尝试使用以下代码片段。字段名称 'title' 区分大小写。
<head>
<title></title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2015.2.902/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2015.2.902/styles/kendo.material.min.css" />
<script src="https://kendo.cdn.telerik.com/2015.2.902/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2015.2.902/js/kendo.all.min.js"></script>
</head>
<body>
<div id="gridError"></div>
<script>
var dataSource = new kendo.data.DataSource({
data: '<books><book id="1"><title>Secrets of the JavaScript Ninja</title></book></books>',
schema: {
// specify the the schema is XML
type: "xml",
// the XML element which represents a single data record
data: "/books/book",
// define the model - the object which will represent a single data record
model: {
// configure the fields of the object
fields: {
// the "title" field is mapped to the text of the "title" XML element
title: "title/text()"
}
},
schema: {
model: {
fields: {
title: { editable: false, nullable: true }
}
}
}
}
});
var pc = $("#gridError").kendoGrid({
//excel: { fileName: "Client Orders.xlsx", filterable: true },
dataSource: dataSource,
scrollable: true,
pageable: true,
navigatable: true,
columns: [
{ command: "destroy", width: 100 },
{
title: "Error Message",
//lock: true,
columns: [
{ field: "title", title: "Error", width: 600 }
],
}
]
});
</script>
</body>
如有任何疑问,请告诉我。