knockout.js
を使用して、配列にバインドされたテンプレートによって作成された要素にフォーカスを設定するにはどうすればよいですか?knockout.jsテンプレートにフォーカスを設定する
テーブルにバインドされた観測可能な配列があります。各行は、配列要素のプロパティを編集できる入力要素のセットです。一番下には"Add"
ボタンがあり、新しい要素を配列にプッシュし、入力フィールドの新しい行を作成します。
"Add"
ボタンが押された後、最初に新しく作成された入力フィールドにフォーカスが設定されます。
HTML:
Javascriptを:現在、あなたはこのようなコード持って
function Attribute(id, name, description, hardcoded) {
var self=this;
self.AttributeID=ko.observable(id || 0);
self.Name=name || '';
self.Description=description || '';
self.HardCoded=hardcoded || false;
self.nameFocus = true;
}
function AttributeSchema(attributeArray) {
var self=this;
// Properties
self.Attributes=ko.observableArray(attributeArray);
// Operations
self.addAttribute=function() {
self.Attributes.push(new Attribute());
};
self.removeAttribute=function() {
self.Attributes.remove(this);
};
}
var vmSchema=new AttributeSchema(
[
new Attribute(5, 'FirstName', 'First Name', true),
new Attribute(6, 'LastName', 'Last Name', true),
new Attribute(7, 'Blah', 'Blah', false)
]
);
ko.applyBindings(vmSchema);
を解決
:で
:
私はその後、置き換え:私はこのような結合 "一方向" hasfocusを作成し、これを解決するために
ありがとう、完璧な答え! Knockout.jsの岩! – Richard