クリックすると、observableArray 内の 1 つのオブジェクトが表示されるインターフェイスを作成していますselected。配列内の現在selectedのオブジェクト (そのうちの 1 つだけである必要があります) は、それらの (その)selectedオブザーバブルを変更する必要があります。
selectedクリックした要素を true に設定する前に、すべての s を false に設定して、クリック時に配列全体を反復処理する必要がありますselectedか?
self.selectAnnotation = function() {
var array = //annotations array from AnnotationsViewModel
// (actually, I'm not so sure of the syntax of this either)
for (var i = 0; i < array.length(); i++) {
var item = array[i];
item.selected(0);
}
self.selected(1);
}
次のようなバインディングを使用します。
<div id="clickArea" data-bind="foreach: annotations">
<span data-bind="click: selectAnnotation, css: selected: selected" class="annotation"></span>
</div>