0

アプリケーション テンプレート内にフラッシュ (メッセージ) ビューを実装しました。アプリケーションの msg 属性を使用して、サイト全体のメッセージを表示します。

<div class='application-main container'>
  {{#if msg}}
    {{view Yu.FlashView}}
  {{/if}}

  {{outlet}}
</div>

私のルーターの一部:

Yu.Router.map ->
  @resource 'user', { path: '/users/:user_id' }

そしてユーザールート:

Yu.UserRoute = Em.Route.extend
  model: (params) ->
    Yu.User.find(params.user_id)

  setupController: (controller, model) ->
    @_super controller, model

    @controllerFor('avatar').set 'model', model.get('avatar')
    @controllerFor('basicinfo').set 'model', model.get('basicinfo')

  renderTemplate: (controller, model) ->
    @_super controller, model

    @render 'avatar', into: 'user', outlet: 'avatar'
    @render 'basicinfo', into: 'user', outlet: 'basicinfo'

ユーザールートに入るとわかるように、basicinfoコントローラーをセットアップしてアウトレットに入れました。質問は次のとおりです。basicinfoコントローラーにアプリケーションコントローラーが「必要」ですが、機能していないようです:

Yu.BasicinfoController = Em.ObjectController.extend
  needs: 'application'.w()

  update: ->
    @content.save()
    @content.on('becameInvalid', ->
      window.console.log(Em.inspect(@get('controllers.application')))  !-> prints "undefined"
      @get('controllers.application').set 'msg', 'please refresh'      !-> msg did not show
    )
    @set 'inEditModel', false

そして、私は必要なAPIと非常に混乱しています.ここで何が問題なのですか? ありがとう!

4

1 に答える 1

1

コードの何が問題なのかよくわかりませんが、これが機能することを示す簡単な例を次に示します: http://jsfiddle.net/scottned/NQKvy/32/

<script type="text/x-handlebars" data-template-name="index">
  <ul>
    {{#each customer in customers}}
      <li>{{customer.firstName}} {{customer.lastName}}</li>
    {{/each}}
  </ul>
</script>

App = Ember.Application.create({});

App.ApplicationController = Em.ObjectController.extend({
    people: [
      {firstName: 'Kris', lastName: 'Selden'},
      {firstName: 'Luke', lastName: 'Melia'},
      {firstName: 'Formerly Alex', lastName: 'Matchneer'}
    ]
});

App.IndexController = Em.ObjectController.extend({
    content: Em.Object.create({}),
    needs: 'application',
    customersBinding: 'controllers.application.people'
});
于 2013-07-19T16:54:46.160 に答える