使用数据绑定到图像 src 属性的淘汰赛模板不起作用 [英] Knockout template using data-bind to image src property not working

查看:17
本文介绍了使用数据绑定到图像 src 属性的淘汰赛模板不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看不出这里有什么问题,但使用以下 Knockout 模板无法显示图像:

绑定的对象如下所示:

tut.myObject= function (imagePath, label) {this.label = ko.observable(label);this.imagePath = ko.observable(imagePath || liveString + '/Content/images/marker.png');};tut.myObject.prototype = {doSomething:函数(){警报(做什么?");}};

当 HTML 对象呈现时,我会看到标签并单击复选框调用 doSomething.

TIA.

解决方案

可以直接绑定的只有少数属性;尝试使用 attr - 它可以让您在元素上设置任何属性.

<img width="16px" height="16px" data-bind="attr:{src: imagePath}"/>

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?");
     }
};

When the HTML object is rendered I see the label and clicking on the checkbox invokes doSomething.

TIA.

解决方案

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 属性的淘汰赛模板不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆