1

我必须在 Tabstrip 的每个选项卡单击上动态加载不同的 KENDO 模板。所有选项卡的数据源都是相同的。我正在尝试按以下方式进行操作,但它不起作用。请告知。(剑道 TabStrip 和剑道模板)

<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,
});
4

2 回答 2

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 属性中放了什么并不重要,因为它会在选择时被替换。

这是我的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>

这是你要找的吗?

于 2017-12-19T15:48:14.563 回答
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,
});
于 2017-03-22T15:20:13.883 回答