I'm fairly new to Knockout.js so I may simply be missing something. I'm trying to create a set of divs that work as buttons where their 'selected' state reflects a subvalue of an item in an array.
See this fiddle: http://jsfiddle.net/bleiddyn/RepnY/
Excerpt:
$('.tag-cell').click(function() {
var ele = event.srcElement.textContent;
var match = ko.utils.arrayFirst(self.Tags(), function(item) {
if (ele === item.title) {
item.chosen = !item.chosen;
return true;
}
return false;
});
match.chosen = true;
self.Tags.valueHasMutated();
});
The initial display of the divs is correct. It seems that I can make the click event change the value inside the observable array without issue. The displayed divs do not change css class in response to this though.
I realize that the children of an object that is an item in an array are not, by themselves, observable. However, shouldn't my call to valueHasMutated() force the issue? This is likely also not the most elegant way to accomplish the behavior.
Anyone want to help a learning javascript guy out?