【发布时间】:2013-08-02 17:01:43
【问题描述】:
在这个 JS Fiddle 中是否有触发更新我的元素的 title 属性:
请注意,元素的 data-bind 属性中的工具提示是 knockout-bootstrap.js 库的一部分
<label data-bind="text: copyOtherPartyHelpText()"></label>
<br />
<br />
<i class="icon-question-sign" data-bind="tooltip: { title: copyOtherPartyHelpText(), placement: 'top', trigger: 'hover' }"></i>
<br />
<br />
<a style="cursor: pointer;" data-bind="click:changeHelpText">Click HERE To Change Label Text</a>
function MyViewModel() {
this._copyOtherPartyHelpText = ko.observable();
this.readOnlyView = ko.observable(true);
this.copyOtherPartyHelpText = ko.computed({
read: function () {
var value = this._copyOtherPartyHelpText();
if (value) {
return value;
}
if (this.readOnlyView()) {
value = 'Currently Disabled';
} else {
value = 'Match/agree to this term.';
}
//this makes things even worse, it is an initialization workaround
//_copyOtherPartyHelpText(value);
return value;
},
write: function (value) {
this._copyOtherPartyHelpText(value);
},
owner: this
});
this.changeHelpText = function(){
this.copyOtherPartyHelpText('help text updated but not tooltip');
}
}
ko.applyBindings(new MyViewModel());
【问题讨论】:
-
看起来你没有正确地制作 viewModel。
-
这是我非常大的 viewModel 的摘录;)
-
好吧,我们不能告诉你他的问题是什么,只有一半的问题。请尝试在较小的示例中重新创建问题,最好使用jsfiddle.net
-
添加了一个小提琴,谢谢!