我不知道爲什麼我的currentTitle
在點擊時沒有改變。敲擊可觀察變量不會改變其點擊值
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);
這裏發佈我的代碼:http://jsfiddle.net/devnegikec/TBP43/
[設置可觀察在淘汰賽不更新值可能重複](http://stackoverflow.com/questions/19391415/setting-value-of-observable-not-updating-in-knockout) – nemesv
如果您對此感到滿意並請您充分回答您的問題,請標記爲已接受的答案。 – phuzi