意見:
<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 値を使用せずに直接バインドするとボーナスになります。どちらの方法でも解決策をいただければ幸いです。