这里出了什么问题?为什么 View 中的 contentBinding 不起作用?
输出
View 中的内容未定义
路由器.咖啡
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.IntroController
是 Ember.Object
的子类,而不是实例。
您需要一个App.ShowController
来指定它需要:
App.ShowController = Ember.Controller.extend({
needs: ['intro']
});
然后在 View 中您将可以访问:controllers.intro.content
。
关于javascript - Ember JS : contentBinding not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14912895/