0

カスタム ビューを通常のビューに書き直しています。例えば

Pseudo code
if (date = today) {
    context.push('...; style="color:red; ...}
else {
    context.push('...; style="color:black; ...}
;

になる

mondayLabelView: SC.LabelView.extend({
        layout: {top:90, left:700, width:200, height:18},
        classNames: ['App-monday'],
        valueBinding: SC.Binding.oneWay('App.someController.selectedMondayDate'),
        }),

質問、ダイナミックカラーの部分を書き換える方法を教えてください。

4

2 に答える 2

1

classNameBindingsプロパティを使用して CSS クラスを動的に追加することをお勧めします。styleこの方法では、タグを使用する必要はありません。

詳細はhttp://blog.sproutcore.com/classnamebindings-easy-dynamic-css/で確認できますが、基本的な考え方は次のとおりです。

mondayLabelView: SC.LabelView.extend({
   layout: {...},
   valueBinding: SC.Binding.oneWay('App.someController.selectedMondayDate'),
   isToday: function() {
     // Psuedo-code, you'll probably need SC.DateTime to actually compare the dates
     return this.get('value') == today;
   }.property('value'),
   classNameBindings: ['isToday:date-is-today'],
})

次に、CSS では次のようになります。

.date-is-today {
  color: red;
}
于 2016-09-12T15:35:07.093 に答える