knockout.jsのドキュメントには、次のような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);
};
};
ただし、これは選択リストの幅を拡大するものではありません。私は何が間違っているのですか?