knockoutjs if 绑定问题
if 绑定似乎对我不起作用。这是我的模板:
<div>
<span data-bind="text: name"></span>
<div data-bind="if: false ">+<span data-bind="text: priceFormatted"></span></div>
</div>
if: false
是作为烟雾测试存在的,因为无论我在那里放什么,跨度总是会显示。我做错了什么?
The if binding doesn't seem to be working for me. Here is my template:
<div>
<span data-bind="text: name"></span>
<div data-bind="if: false ">+<span data-bind="text: priceFormatted"></span></div>
</div>
The if: false
is there as a smoketest, because no matter what I put there, the span always shows up. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 v1.1.2 时它会崩溃,但在 v2.0 中工作得很好。请参阅此 jsfiddle。也许您需要使用更高版本的 Knockout.JS?
It breaks using v1.1.2, but works just fine in v2.0. See this jsfiddle. Maybe you need to use the later version of Knockout.JS?
我试过你的例子,它对我来说效果很好。
您的页面底部是否有脚本引用以确保整个 DOM 已加载?
例如,这是我的文件之一:
I tried you're example and it's working fine for me.
Do you have your script references at the bottom of your page to make sure the entire DOM has loaded?
For example, here is one of my files: