【问题标题】:EmberJS: contentBinding not workingEmberJS:内容绑定不起作用
【发布时间】:2013-02-01 12:02:52
【问题描述】:

这里有什么问题?为什么视图中的 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')

【问题讨论】:

    标签: javascript coffeescript ember.js


    【解决方案1】:

    这是因为App.IntroControllerEmber.Object 的子类,而不是实例。

    你需要一个App.ShowController 来指定它需要什么

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-11
      • 1970-01-01
      • 2012-11-02
      • 2018-06-14
      • 2012-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多