【发布时间】: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 的页面。
【问题讨论】:
-
您是否尝试过
$root、$parent甚至$parents[]上下文?基于knockoutjs.com/documentation/binding-context.html -
好吧,我试过了:$root、$page、$parent、$parents、$context 所有这些都检索未定义。 . .
标签: typescript knockout.js kendo-template kendo-listview