基於你的樣品快速劈...
添加可觀察到保持當前排序類型
self.sorttype = ko.observableArray(['Score', 'Count', 'Average']);
self.selectedSort = ko.observable('Score');
改變綁定設置selectedSort在onclick
var value = valueAccessor();
var prop = value.prop;
var data = value.arr;
// set the current sort type
// this binding in inside a foreach, so you need to get the parent model
bindingContext.$parents[1].selectedSort(prop);
更改跨度數據綁定。您在小提琴(2.1)中使用的敲除版本有一個錯誤,其中以下語法生成綁定異常。升級到2.3或3.0可以修復它。如果你不能改變淘汰賽版本,那麼你就需要使用ko.computed
<span class="input-group-addon" data-bind="text: $data[$parents[1].selectedSort()]"></span>
編輯
感謝您指出與過去的那種獨立的明顯的監督;)
移動selectedSort到集合對象
collection.FaveListItems = data;
collection.Count = data.length;
collection.selectedSort = ko.observable('Score');
改變bindingHander從$家長[1]到$父
bindingContext.$parent.selectedSort(prop);
改變文本的下拉
<a class="btn dropdown-toggle" data-bind="text: selectedSort" data-toggle="dropdown"></a>
更改文本對行跨度
<span class="input-group-addon" data-bind="text: $data[$parent.selectedSort()]"></span>
非常感謝。我更新了小提琴:http://jsfiddle.net/pyCTN/117/只需幾件事,你的解決方案更新集合中的所有數組,而不僅僅是所選的一個。 – user1405195