knockout.js 문서는 다음과 같이 바인딩 CSS를 보여줍니다 클릭변경 CSS 클래스는
<div data-bind="css: { profitWarning: currentProfit() < 0 }">
Profit Information
</div>
나는 마우스 클릭에 CSS 클래스를 변경하는 데 적응해야합니다. 어떻게해야합니까? 아래의 답변을 바탕으로
는,이 같은 일부 코드를 사용하고 있습니다 :
// CSS class to be applied
<style>
.bigclass
{
width: 200px;
}
</style>
// Select list inside a jquery .tmpl
<script id='criteriaRowTemplate' type='text/html'>
<tr>
<td>
<select data-bind='click: makeBig, css: {bigclass : SelectHasFocus() > 0}' />
</td>
</tr>
</script>
// Knockout.js Viewmodel
var CriteriaLine = function() {
this.SearchCriterion = ko.observable();
this.SelectHasFocus = ko.observable(0);
// this method is called
makeBig = function(element) {
this.SelectHasFocus(1);
};
};
그러나이 선택 목록의 폭을 확대하지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
나는 당신이 가정을'ko.applyBindings (CriteriaLine())'어딘가에 문서를로드 한 후, 맞죠? 귀하의 코드는 [여기] (http://jsfiddle.net/6896T/4/)와 같이 작동합니다. 너의 대답에 대해 – Pakman