我成功地以下列方式使用淘汰赛:
<div id="Options" data-bind="foreach: Options">
<button type="button" data-bind="css: { selected: IsSelected }, enable: $parent.allow, click: $parent.select"><img src="/path/to/img.png"/></button>
</div>
现在,我正在尝试使用以下内容将按钮更改为图像:
<div id="Options" data-bind="foreach: Options">
<input type="image" data-bind="css: { selected: IsSelected }, attr:{src:/path/to/img.png}, enable: $parent.allow, click: $parent.select" />
</div>
我的目标是使用淘汰赛将每个选项与自己的图像配对。
按钮没有加载第二个选项,所以我认为语法已关闭。知道为什么它不起作用吗?
答案 0 :(得分:1)
您设置图像源的方式是错误的。您试图将其设置为字符串的值,但您需要将其写为字符串文字(即带引号)。您能够在其他绑定中设置没有它们的绑定的原因是因为它们是视图模型的属性。
其中任何一个都应该有效:
<input type="image" data-bind="css: { selected: IsSelected }, attr:{src:'/path/to/img.png'}, enable: $parent.allow, click: $parent.select" />
<input type="image" src="/path/to/img.png" data-bind="css: { selected: IsSelected }, enable: $parent.allow, click: $parent.select" />