Ember.Componentを使用した 1 つのソリューションを次に示します。
App.InlineEditComponent = Ember.Component.extend({
actions: {
toggleEditing: function() {
this.toggleProperty('isEditing');
}
}
});
テンプレートを使用する場合:
<script type="text/x-handlebars" id="components/inline-edit">
{{#if isEditing}}
<form {{action "toggleEditing" on="submit"}}>
{{yield}}
</form>
{{else}}
<span {{action "toggleEditing"}}>
{{value}}
</span>
{{/if}}
</script>
使用法:
<script type="text/x-handlebars" data-template-name="index">
{{#inline-edit value=someProperty}}
{{input value=someProperty type="date"}}
{{/inline-edit}}
</script>
デモ: http://emberjs.jsbin.com/OGEnOdA/2/edit
さらに機能を追加することもできます (たとえば、フォーム要素のフォーカス アウトで編集を終了するなど) が、基本的な考え方は理解できたと思います。