燃えさしを手に入れたと思ったら、これが起こり、レンガの壁にぶつかります。
私は持っている
App.Router.map(function() {
this.resource('customers', function() {
this.resource('customer', {
path : ':customer_id'
});
顧客ルート:
App.CustomersRoute = Ember.Route.extend({
model: function() {
return this.store.find('customer');
},
顧客コントローラ:
App.CustomerController = Em.ObjectController.extend({
needs: ['state'],
isEditing: false,
isNotEditing: Ember.computed.not('isEditing'),
actions : {
startEditing: function() {
this.set('isEditing',true);
this.set('validationErrors', '');
},
save: function() {
およびこれらのテンプレート:
<script type="text/x-handlebars" data-template-name="customers">
...
{{outlet}}
...
</script>
<script type="text/x-handlebars" data-template-name="customer">
...
{{#if isEditing}}
<div class="well well-sm">
<a class="btn btn-success" {{action save}}>Save</a>
<a class="btn btn-warning" {{action cancel}}>Cancel</a>
</div>
{{else}}
<div class="well well-sm">
<a class="btn btn-primary" {{action startEditing}}>Edit</a>
<a class="btn btn-danger" {{action delete}}>Remove</a>
</div>
{{/if}}
これはすべて私にとってうまくいっています。顧客を選択し、編集ボタンを押すと、フォーム入力が有効になり、保存ボタンを押すと、変更されたデータがデータベースに永続化されます
ただし、これは私のレンガの壁です。
新しいレコードを作成する機能を有効にするにはどうすればよいですか : 編集フォームを複製したくありません。空白を表示するだけです
ルーターマップに「new」を入れる必要があると仮定しています
this.resource('customers', function() {
this.resource('customer', {
path : ':customer_id'
});
route('new');
});
しかし、CustomerNew コントローラと CustomerNew ルートと CustomerNew テンプレートを作成する必要がありますか?
顧客コントローラーにアクションを入れました
<a class="btn btn-primary btn-xs pull-right" {{action startNew}}>New</a>
新しいアクションを処理するためだけにルートとコントローラーとテンプレートを作成する必要がありますか? または、 customer/1 route/controller/template を再利用できますか?
ありがとう