我必须在Tabstrip的每个标签页上动态加载不同的KENDO模板。所有选项卡的数据源都相同。我试图这样做,但它不起作用。请指教。(Kendo TabStrip和Kendo模板)
<div class="tabs-details-wrapper" id="Tab1">
<ul>
<li class="k-state-active" >Identification</li>
<li>Planning</li>
<li>Implementation</li>
<li>Review</li>
<li>Management Response</li>
</ul>
<div>
<div class="row">
<div class="col-xs-12 col-md-5">
<div class="">
<div class="form-horizontal" ></div>
</div>
</div>
</div>
</div>
</div>
<script id="details-templateTab1" type="text/x-kendo-template">
<div class="form-group">
<label class="col-xs-12 col-md-4 control-label">Year of Completion</label>
<div class="col-xs-12 col-md-8">
<span class="control-readonly"></span>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-md-4 control-label">Title</label>
<div class="col-xs-12 col-md-8">
<span class="control-readonly"></span>
</div>
</div>
</script>
<script id="details-templateTab2" type="text/x-kendo-template">
<div class="form-group">
<label class="col-xs-12 col-md-4 control-label">Hello1</label>
<div class="col-xs-12 col-md-8">
<span class="control-readonly">
</span>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-md-4 control-label">Title1</label>
<div class="col-xs-12 col-md-8">
<span class="control-readonly">
</span>
</div>
</div>
</script>
$(".tabs-details-wrapper").kendoTabStrip({
select: function (e) {
//var data = this.dataSource.at($(e.item).index());
var templateSelector = ""
// alert(e);
if (e.item.innerText == "Identification") templateSelector = kendo.template($("#details-templateTab1").html())
else templateSelector = kendo.template($("#details-templateTab2").html()) ;
// alert(e.contentElement);
//templateSelector = kendo.template($("#details-templateTab1").html());
$(e.contentElement).html(templateSelector);
// kendo.bind(e.contentElement, data);
// $(e.contentElement).html(template(this.dataSource.at($(e.item.innerText).index())))
},
// template: $("#details-templateTab1"),
animation: false
//dataSource: ds
// dataSource: ds,
});
答案 0 :(得分:1)
我已经开始jsBin来帮助解决您的问题。当我点击每个标签时,它会像你所说的那样加载内容。您是否有要添加到代码中的数据源javascript对象?
请提供更多信息。
$(".tabs-details-wrapper").kendoTabStrip({
select: function (e) {
//var data = this.dataSource.at($(e.item).index());
var templateSelector = ""
// alert(e);
if (e.item.innerText == "Identification") templateSelector = kendo.template($("#details-templateTab1").html())
else templateSelector = kendo.template($("#details-templateTab2").html()) ;
// alert(e.contentElement);
//templateSelector = kendo.template($("#details-templateTab1").html());
$(e.contentElement).html(templateSelector);
// kendo.bind(e.contentElement, data);
// $(e.contentElement).html(template(this.dataSource.at($(e.item.innerText).index())))
},
// template: $("#details-templateTab1"),
animation: false
//dataSource: ds // what is your DS?
// dataSource: ds,
});
答案 1 :(得分:1)
我认为问题在于您的数据源中没有定义“dataContentField”。一旦我将其与数据源一起添加,我就开始看到select函数的动态结果。
这是我的JavaScript
$(".tabs-details-wrapper").kendoTabStrip({
select: function (e) {
var templateSelector = ""
if (e.item.innerText == "Identification") templateSelector = kendo.template($("#details-templateTab1").html())
else templateSelector = kendo.template($("#details-templateTab2").html());
$(e.contentElement).html(templateSelector(this.dataSource.at($(e.item).index())))
},
animation: false,
dataTextField: "Name",
dataContentField: "Content",
dataSource: [
{ Name: "Identification", YearOfCompletion: "1998", Title: "This is first title", Content: "", customMessage: "This is custom message 1" },
{ Name: "Planning", YearOfCompletion: "1999", Title: "This is second title", Content: "", customMessage: "This is custom message 2" },
{ Name: "Implementation", YearOfCompletion: "2000", Title: "This is third title", Content: "", customMessage: "This is custom message 3" },
{ Name: "Review", YearOfCompletion: "2001", Title: "This is fourth title", Content: "", customMessage: "This is custom message 4" },
{ Name: "Management Response", YearOfCompletion: "2002", Title: "This is fifth title", Content: "", customMessage: "This is custom message 5" }
]
});
我在dataSource的content属性中输入的内容并不重要,因为这会在select上被替换。
这是我的HTML
<div class="tabs-details-wrapper" id="Tab1"></div>
<script id="details-templateTab1" type="text/x-kendo-template">
<div class="form-group">
<label class="col-xs-12 col-md-4 control-label">Year of Completion</label>
<div class="col-xs-12 col-md-8">
<span class="control-readonly">#=YearOfCompletion#</span>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-md-4 control-label">Title</label>
<div class="col-xs-12 col-md-8">
<span class="control-readonly">#=Title#</span>
</div>
</div>
</script>
<script id="details-templateTab2" type="text/x-kendo-template">
<div class="form-group">
<label class="col-xs-12 col-md-4 control-label">Hello1</label>
<div class="col-xs-12 col-md-8">
<span class="control-readonly">#=customMessage#</span>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-md-4 control-label">Title1</label>
<div class="col-xs-12 col-md-8">
<span class="control-readonly">#=Title#</span>
</div>
</div>
</script>
这是你想要的吗?