[knockoutjs if和ifnot绑定在模板内部使用时无法正常工作

问题描述 投票:1回答:2

我正在使用以下模板与剔除js

<tbody data-bind="foreach: List">
            <tr>
                <td><input type="button" data-bind="if: ($parent.IsFVL || $parent.AllowChat || $root.Me().AllowChatMonitoring), value: ID, click: SelectVisit" /><span data-bind="ifnot: ($parent.IsFVL || $parent.AllowChat || $root.Me().AllowChatMonitoring), text: ID"></span></td>...

并像这样调用/启动模板

<div data-bind="template: { name: 'tplVisitsGrid', data: { Title: 'My Visits', 'List': MVL, 'AllowChat': true, 'AllowPing': false, 'IsFVL': false } }"></div>

此外,我还仔细检查了“ $ root.Me()。AllowChatMonitoring”的值为true,但input [type = button]和span都在呈现。我可能会缺少什么?

knockout.js knockout-2.0
2个回答
0
投票

访问IsFVL,AllowChat等时,您不应使用$parent。尝试将模板更新为以下内容:

<input type="button" data-bind="if: (IsFVL || AllowChat || $root.Me().AllowChatMonitoring), value: ID, click: SelectVisit" />
<span data-bind="ifnot: (IsFVL || AllowChat || $root.Me().AllowChatMonitoring), text: ID"></span></td>

如果这无济于事,请摆弄您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.