使用数据绑定到图像src属性的Knockout模板不起作用 [英] Knockout template using data-bind to image src property not working
本文介绍了使用数据绑定到图像src属性的Knockout模板不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看不到这里出了什么问题,但是使用以下Knockout模板不能显示图像:
I cannot see what is wrong here but the image does not display using the following Knockout template:
<script type="text/html" id="legend-template">
<div><input type="checkbox" data-bind="click : doSomething" ></input>
<img width="16px" height="16px" data-bind="src: 'imagePath'" />
<span data-bind="text : label"> </span>
</div>
</script>
被绑定的对象如下所示:
The object this is being bound to looks like this:
tut.myObject= function (imagePath, label) {
this.label = ko.observable(label);
this.imagePath = ko.observable(imagePath || liveString + '/Content/images/marker.png');
};
tut.myObject.prototype = {
doSomething: function () { alert("do what?");
}
};
当HTML对象呈现时,我看到标签,然后单击复选框将调用doSomething。
When the HTML object is rendered I see the label and clicking on the checkbox invokes doSomething.
TIA。
推荐答案
只有几个属性可以直接绑定;尝试使用 attr
- 它将允许您设置元素上的任何属性。
Only a few attributes can be bound directly; try using attr
- it will let you set any attribute on an element.
<img width="16px" height="16px" data-bind="attr:{src: imagePath}" />
这篇关于使用数据绑定到图像src属性的Knockout模板不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文