Development Tip

이미지 src 속성에 데이터 바인딩을 사용하는 녹아웃 템플릿이 작동하지 않음

yourdevel 2020. 11. 16. 22:19
반응형

이미지 src 속성에 데이터 바인딩을 사용하는 녹아웃 템플릿이 작동하지 않음


여기서 무엇이 잘못되었는지 볼 수 없지만 다음 녹아웃 템플릿을 사용하여 이미지가 표시되지 않습니다.

<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>

이것이 바인딩되는 객체는 다음과 같습니다.

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이 호출됩니다.

TIA.


몇 가지 속성 만 직접 바인딩 할 수 있습니다. 사용해보십시오 attr-요소에 속성을 설정할 수 있습니다.

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

참고 URL : https://stackoverflow.com/questions/10659665/knockout-template-using-data-bind-to-image-src-property-not-working

반응형