0

コードは機能し、コードの jsfiddleは次のとおりです。しかし、 {[render}}を機能させるために使用しているアプローチが好きではありません。今のところ、application-template で{{render events}}を使用できるようにするには、setupController を使用して application-route に設定し、次にcontrollerFor('events')を呼び出す必要があります。そうしないと機能しません。しかし、コントローラ コンテンツをセットアップするためのモデル フックを使用して EventsRou​​te を既に定義しており、{{render helper}}が EventsRou​​te で設定されたモデルを使用することを好みます。

ApplicationRoute に行くという私の現在のアプローチ以外に、これを ember で行うためのより良い、またはより慣用的な方法があるかどうか疑問に思っていました

関連コード*

  App.Router.map(function(){
    this.resource('events');
  });

アプリケーション テンプレートの {{render 'events'}} は、アプリケーション ルートを介してモデルを設定した場合にのみ機能します。

 App.ApplicationRoute = Ember.Route.extend({
   setupController: function(){
     this.controllerFor('events').set('model', App.Event.find());        
   }
 });

{{render 'events'}} を使用して、ここで設定したコンテンツを操作したいのですが、そうではありません。しかし、{{#linkTo}} を使用することが理にかなっている可能性がある場所で使用するために、今のところ使用し続けています。

 App.EventsRoute = Ember.Route.extend({
    model: function(){
    return App.Event.find();  
    },

   setupController: function(controller, model){ 
         controller.set('content', model);
    }
});

テンプレート

   <script type="text/x-handlebars" data-template-name="application">
     {{render 'events'}}
      {{outlet}}
  </script>

  <script type="text/x-handlebars" data-template-name="events">

        <button {{action 'yEmpty'}}> log event content is empty</button>

       {{#each controller}}
        <h3>{{title}}</h3>
       <p>{{start}} - {{end}}</p> 
      {{/each}}
    {{outlet}}
 </script>
4

1 に答える 1