Kendo ui 将XML子元素映射到Kendo UI数据源
我正在努力使用KendoUIMobile在XML数据源上映射和显示子元素列表 考虑以下简单的XML结构:Kendo ui 将XML子元素映射到Kendo UI数据源,kendo-ui,kendo-mobile,Kendo Ui,Kendo Mobile,我正在努力使用KendoUIMobile在XML数据源上映射和显示子元素列表 考虑以下简单的XML结构: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <topics> <topic id="1" title="Weather"> <header>Great weather today!</header> <smallicon
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<topics>
<topic id="1" title="Weather">
<header>Great weather today!</header>
<smallicon>foo_bar.png</smallicon>
<items>
<item>It's great weather</item>
<item>Sunny feeling</item>
<item>Raining like a dog</item>
</items>
</topic>
<topic id="2" title="Politics">
<header>Left or right, take your pick!</header>
<smallicon>whatever.png</smallicon>
<items>
<item>Making budget cuts</item>
<item>How important is healthcare?</item>
</items>
</topic>
</topics>
对于顶层的属性和元素来说,这似乎很好地融合了。我得到了一个主题列表,可以使用类似于:data.title.
的东西将它们绑定到模板。这里没有问题
但是,我还想为每个
映射子元素。在XML示例中,这表示
的列表。这是我感到困惑的“如何映射这个模式”部分
最终的目标是显示这些子项的列表,例如::data.items[0].
此外,我还尝试了一种新的方法,但常规的数据源似乎工作得很好。也许这更合适?KendoAPI文档似乎没有提供具有嵌套层次结构的XML示例
关于如何实现这一点,有什么建议吗?经过反复尝试,我想出了以下解决方案:
schema: {
type: "xml",
data: "/topics/topic",
model: {
fields: {
id: "@id",
title: "@title",
header: "header/text()",
smallicon: "smallicon/text()",
// > ANWER: THIS IS HOW
children: "items"
},
hasChildren: "items"
}
}
与我原来的问题相比,这个片段有两个变化:
// fetch the one, single topic from the datasource
topic = dataSource.Topics.get(topicId);
// read the inner contents, e.g. text, from a single <items> node
log(topic.children.item[0]["#text"]);
//从数据源中获取一个主题
topic=dataSource.Topics.get(topicId);
//从单个节点读取内部内容,例如文本
日志(topic.children.item[0][“#text”]);
也许这对将来的其他人有一些帮助
// fetch the one, single topic from the datasource
topic = dataSource.Topics.get(topicId);
// read the inner contents, e.g. text, from a single <items> node
log(topic.children.item[0]["#text"]);