【发布时间】:2019-06-14 14:36:12
【问题描述】:
在我的淘汰赛申请中,我试图比较两个可观察值并相应地分配类。
但是 observable 的评估不会改变事件,尽管值在 observable 中发生了变化
下面是代码
<div class="col-lg-4 col-sm-4 col-xs-4 text-center">
<span data-bind="text:CurrentPlan().Id "></span>
<span data-bind="text:CurrentElem().PointPlanId "></span>
<span data-bind="text:CurrentPlan.Id == CurrentElem.PointPlanId"></span>
<button class="btn btn-blue btn-alt" type="button" data-bind="click:AssignPlan,
css: {'disabled':CurrentPlan.Id == CurrentElem.PointPlanId}"> Assign </button>
</div>
我可以看到添加的 span 中的值发生了变化,但表达式值没有变化。
currentPlan 和 currentElem 都是 observables。
请指导
谢谢
Shruti nair
【问题讨论】:
-
您忘记了获取可观察值所需的
()。试试CurrentPlan().Id == CurrentElem().PointPlanId -
即使值相同,也无法将其评估为 false。
-
如果解决了您的问题,请mark the answer as accepted。
标签: javascript knockout.js observable