【问题标题】:Getting the $page context on a kendoListView template在 kendoListView 模板上获取 $page 上下文
【发布时间】:2018-07-15 22:23:11
【问题描述】:

我正在使用 kendoListView,我只想显示满足我的 if 条件的项目:

<div id="selectableListView" data-bind="kendoListView: { data: dataSource._kendoDataSource, template: $('#template_selectable').html(), selectable: true, change: changeMultiSelection, navigatable: true, dataBound: productsRetrieved}"> </div>

<script type="text/x-kendo-tmpl" id="template_selectable">
    #if(variableFromPageId !== Id){#
    <div class="principal">
        <div class="list-view-details">
            <div class="secction-top">
                <div class="item-name-two-lines item-name-link">
                    <a class="link"> #:Project.Utils.getDefaultName(Name)# </a>
                </div>
            </div>
            <div class="secction-center">
                <span class="item-description-two-lines">#:Project.Utils.getDefaultDescription(Description)#</span>
            </div>
        </div>
    </div>
    #}else{#
        console.log('Do nothing!');
    # }#
</script>

问题是 variableFromPageId 位于我的页面上下文中,并且列表视图无法访问该上下文我如何从调用 kendoListView 的页面访问变量?或将 variableFromPageId 作为变量发送。我尝试了很多方法,例如:

<div data-bind="if: checkId(Id)">
</div>

#console.log(ko.contextFor(this).$page.checkId('#:Id#'));#

内部数据绑定在列表视图中根本不起作用,它忽略所有数据绑定,控制台日志的第二个选项说找不到 $page of null,那么我如何从具有 KendoListView 的页面。

【问题讨论】:

标签: typescript knockout.js kendo-template kendo-listview


【解决方案1】:

你的数据源中不能有variableFromPageId,所以你的模板不知道它是什么。

您可以将该值添加到现有数据源中,方法是将该值添加到每个数组值中,或者您可以将不同的数据源传递给模型中较高的 Kendo 模板,例如您的 Knockout $root$parent 值。如果选择后者,则需要在 Kendo 模板中添加自己的 for 语句以循环遍历数组。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-17
    • 2012-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-13
    • 2019-08-11
    • 1970-01-01
    相关资源
    最近更新 更多