2012-12-24 56 views
1

内使用时如不方便绑定都不能正常工作我使用的是淘汰赛JSknockoutjs如果和模板

<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,但输入[type = button]和span都呈现,有人可以帮我解决问题。

谢谢。

回答

0

因为您将多个属性合并到ififnot中,您需要对它们进行评估。试试这个(假设IsFVLAllowChatAllowChatMonitoring都观察到的 - 它们必须):

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

什么是实际发生之前是,它是比较3层的功能,不是的函数的返回值。

+0

这些属性是不可观测的,所以你的建议将无法正常工作。 –

+0

@ArtemVyshniakov对于他们在'If'绑定工作,他们*必须*可观察 – xdumaine

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> 

如果这不会帮助,创建您的问题小提琴。

+0

感谢您的回复,属性IsFVL和AllowChat不是可观察的,不让他们观察的原因是我加载模板三次使用这些属性的不同值,所以我找不到一种方法将它们添加为可观察到的模型。通过检查其他简单的JavaScript表达式在敲除绑定中进行评估,如if,ifnot,visible,但这些props不是。我将为此和帖子创建一个小提琴。 – Liono