1

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

<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。

4

1 回答 1

0

您的数据源中一定没有variableFromPageId,因此您的模板不知道它是什么。

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

于 2018-02-11T05:33:58.317 回答