I don't know why my currentTitle
is not changing on click.
viewModel = {
articles: ko.observableArray([{
id: 1,
title: "Article One",
content: "Content for article one."},
{
id: 2,
title: "Article Two",
content: "Content for article two."},
{
id: 3,
title: "Article Three",
content: "Content for article three."}
]),
currentTitle: ko.observable("old")
};
<div data-bind="foreach: viewModel.articles()">
<div data-bind="text:title,click: getTitle"></div>
</div>
<div data-bind="text: viewModel.currentTitle"></div>
getTitle = function(){
viewModel.currentTitle = "title";
}
ko.applyBindings(viewModel);
Posted my code here : http://jsfiddle.net/devnegikec/TBP43/