看法:
<td style="white-space: nowrap;">
<img data-bind="attr: { onclick: PlaySounds }" src="/Images/audioGreen.png" alt="Pronounce word" title="Pronounce word" style="cursor: pointer" />
<a data-bind="attr: { href: GoogleQuery }" target="_blank">
<img src="/Images/googleIcon.png" alt="Google Search" title="Google Search" style="cursor: pointer" />
</a>
</td>
淘汰赛视图模型:
function DictionaryEntry() {
var self = this;
self.Simplified = ko.observable("");
self.Traditional = ko.observable("");
self.Phonetic = ko.observable("");
self.Definition = ko.observable("");
self.GoogleQuery = ko.computed(function () {
return "http://www.google.com/search?q=" + self.Simplified();
}, self);
self.PlaySounds = ko.computed(function () {
return "playSounds('" + self.Phonetic() + "')";
}, self);
}
关于“attr”绑定的信息:“ http://knockoutjs.com/documentation/attr-binding.html ”
错误详情:
Microsoft JScript 运行时错误:无法解析绑定。消息:ReferenceError:“PlaySounds”未定义;绑定值:attr: { onclick: PlaySounds }
不知道我哪里出错了。如果可能,直接绑定而不使用 ko.computed 值将是一个好处。无论哪种方式的解决方案将不胜感激。