您好我正在尝试在Icentium中编写我的第一个应用程序。我想将智慧存储在json数组中。根据您的等级,您将获得新的智慧。不幸的是,我不知道为什么它会破坏整个json数组。
这是课程.js
(function(global) {
var LessonsViewModel,
app = global.app = global.app || {};
LessonsViewModel = kendo.data.ObservableObject.extend({
lessonsDataSource: null,
init: function () {
var that = this,
dataSource;
kendo.data.ObservableObject.fn.init.apply(that, []);
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "data/lessons/lessons.json",
dataType: "json"
}
}
});
that.set("lessonsDataSource", dataSource);
}
});
app.lessonsService = {
viewModel: new LessonsViewModel()
};
这是视图
<!--Lessons-->
<div id="tabstrip-lesson"
data-role="view"
data-title="Lektion"
data-model="app.lessonsService.viewModel">
<div class="lesson">
<div class="separator">
<div class="dark"></div>
<div class="light"></div>
</div>
<ul class="forecast-list"
data-role="listview"
data-bind="source: lessonsDataSource"
data-template="lessons-template"><!-- Das unten stehende Kendo Template wird hier eingefügt-->
</ul>
</div>
</div>
<!--Lessons Kendo Template für oben-->
<script type="text/x-kendo-tmpl" id="lessons-template">
<div>
<h1>${dojoroom}</h1>
<p>${text}</p><!-- Text aus Json File wird ausgelesen-->
</div>
</script>
这是我的json数组:
[
{
"dojoroom": "Dojo - First Room",
"text": "Bla bla bla!"
},
{
"dojoroom": "Dojo - Second Raum",
"text": "More Bla"
}
答案 0 :(得分:0)
到目前为止,我根据剑道文件(http://docs.kendoui.com/api/framework/datasource)尝试了:
LessonsViewModel = kendo.data.ObservableObject.extend({
lessonsDataSource: null,
init: function () {
var that = this,
dataSource;
kendo.data.ObservableObject.fn.init.apply(that, []);
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "data/lessons/lessons.json",
dataType: "json"
}
}
});
that.set("lessonsDataSource", dataSource.at(0));
}
});
但这根本没有显示任何内容。我也在视图中尝试了dataSource [0]和相同的方法。
dataSource.fetch(function(){
var dojo = dataSource.at(0);
that.set("lessonsDataSource", dojo);
});