我有一个跨度,我用挖空来绑定跨度,以便在页面加载时它可以工作。我试图通过锚标记点击绑定来更改值。
<a href='#'data-bind='click:ViewModel.setVisibility,disable:ViewModel.completeReview '>Show More</a>
<span data-bind="html: ViewModel.getText(Text),visible:ViewModel.completeReview "></span>
然后在我看来模特chage是
self.completeReview = ko.observable(false);
self.setVisibility = function () {
return self.completeReview = true;
};
但它没有反映出可见性。我在firebug中进行了调试。该方法被调用。 有人有任何想法吗?
答案 0 :(得分:0)
您不能像正常变量那样设置observable。并且无需在视图上返回任何内容,因为observable将自动通知对UI的更改。试试这个:
HTML 的
<a href='#'data-bind='click: ViewModel.setVisibility,disable:ViewModel.completeReview '>Show More</a>
<span data-bind="visible:ViewModel.completeReview ">
Click to on Show More to hide or show me.
</span>
JS
function ViewModel()
{
var self = this;
self.completeReview = ko.observable(false);
self.setVisibility = function () {
self.completeReview(!self.completeReview());
};
}
var ViewModel = new ViewModel();
ko.applyBindings(ViewModel);