在setDataSource上更改Kendo Mobile ListView的模板?
问题描述:
我正在使用setDataSource方法更改数据源,但也需要更改模板。动态更改模板似乎不起作用。在setDataSource上更改Kendo Mobile ListView的模板?
下面是我有和jsFiddle在这里:http://jsfiddle.net/MfSup。注意,点击按钮组后,它不会更改为“onFilter”事件中的“模板2”。这是一个错误还是我做错了?
new kendo.mobile.Application();
var ds1 = new kendo.data.DataSource({
data: [{
stagename: "ds1 A",
b: "1b"
}, {
stagename: "ds1 B",
b: "2b"
}]
});
var ds2 = new kendo.data.DataSource({
data: [{
stagename: "ds2 A",
b: "1b"
}, {
stagename: "ds2 B",
b: "2b"
}]
});
var onFilter = function (e) {
var lv = $("#stages_listview")
.data('kendoMobileListView');
//CHANGE TEMPLATE DOESN'T WORK
lv.options.template = this.selectedIndex == 0
? $("#stages_listview_template1").html()
: $("#stages_listview_template2").html();
lv.setDataSource(this.selectedIndex == 0 ? ds1 : ds2);
};
$("#stages_listview").kendoMobileListView({
dataSource: ds1,
template: $("#stages_listview_template1").html()
});
答
下面应该工作:
lv.template = kendo.template("<li data-uid='#=uid#'>" +
(this.selectedIndex == 0 ?
$("#stages_listview_template1").html() :
$("#stages_listview_template2").html()
) +
"</li>");
THX。它看起来像一个错误。我希望它是固定的,或者更好的是,向setDataSource添加可选参数以提供模板。 – TruMan1