EmberJS: contentBinding not working

EmberJS: contentBinding not working

本文关键字:working not contentBinding EmberJS      更新时间:2023-09-26

这里出了什么问题?为什么视图中的contentBinding不起作用?

输出
视图中的内容未定义

router.coffee

App.Router.map ->
  @route "show"
  @route "intro",

intro_controller.coffee

App.IntroController = Ember.ArrayController.extend
  content: []
  createRecords:(files) ->
    @set('content', Ember.A())
    person = Ember.Object.create(username: "hello world")
    @pushObject person
    console.info "content in controller", @get('content')
    @transitionTo 'show'

show_view.coffee

App.ShowView = Ember.View.extend
  contentBinding: 'App.IntroController.content',
  didInsertElement: ->
    console.info "content in view", @get('content')
这是因为App.IntroControllerEmber.Object的子类,而不是实例。

您需要一个指定需要什么的App.ShowController:

App.ShowController = Ember.Controller.extend({
    needs: ['intro']
});

然后在视图中,您将可以访问:controllers.intro.content