ノックアウトで条件付きぼかしの入力値を更新しようとしています - 基本的に、特定の要素がぼかしをトリガーしたときに、要素が値の更新をトリガーしないようにします。ドキュメントのすべての要素を見て、最後にクリックされたものを判断できることはわかってmousedown
いますが、少しやりすぎのようです。誰でも考えられる他の回避策はありますか?
<input class="edit" data-bind="value: title, valueUpdate: 'afterkeydown', enterKey: $root.stopEditing, selected: editing, event: { blur: $root.checkEditing }">
これをやってのけるために私が達成しようとしていたコードは、document.activeElement
.
self.checkEditing = function( item, event ) {
if (document.activeElement == $('a.cancel')) {
// revert to previous title, aka cancel the editing
item.title(item.previousTitle);
item.editing( false );
} else {
// this will update value with whatever was typed right before the blur
item.editing( false );
if ( !item.title().trim() ) {
self.remove( item );
}
}
};