私はあなたのコードの残りの部分にアクセスできないので、ここではやみくもに推測しています。
初め
ko.computed読み取り関数を取るか、readとwrite関数を持つオブジェクトを取ります。read/writeプロパティを持つオブジェクトを返す関数は必要ありません。
例
右:ko.computed -> 5
右:ko.computed { read: -> 5 }
間違っています:ko.computed -> { read: -> 5 }
2番
@つまり、関数の呼び出し方 ( 、、 ) にthis応じて、異なる値を持つ可能性があります。の値を指定したい場合は、 の作成時に を指定できます。f()f.apply(_)new F()thisownerko.computed
computed = ko.computed {
read: -> @getValue()
owner: @
}
例
良い
class Thing
constructor: (@number) ->
self = @
ko.computed -> self.number
コーウェイ
class Thing
constructor: (@number) ->
ko.computed {
read: -> @number
owner: @
}
悪い
class Thing
constructor: (@number) ->
ko.computed -> @number # means this.number
ややこしい (=>)
class Thing
constructor: (@number) ->
ko.computed => @number
ついに
すべてを一緒に入れて。
例
@allChecked = ko.computed {
read: ->
console.log 'allChecked->read()'
firstUnchecked = ko.utils.arrayFirst @contactGroups(), (item) ->
item.IsSelected() == false
firstUnchecked == null
write: (value) ->
console.log 'allChecked->write()', value
group.IsSelected(value) for group in @contactGroups()
owner: @
}