javascript - Ember JS : contentBinding not working

标签 javascript coffeescript ember.js

这里出了什么问题?为什么 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.IntroControllerEmber.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/

相关文章:

javascript - 检测访问者是否来自 Google 搜索的最可靠方法?

javascript - Uglifier 破坏了我的 js 吗?

javascript - 全日历选项不起作用

javascript - `this` 在 json 回调中是不可见的吗?

javascript - 在保存时编译一些 CoffeeScript 文件

javascript - 应该在 Controller 上定义关闭 Action

ember.js - Ember.js 中的可选动态段

javascript - 将 $.getJSON 对象传递给另一个 ember Controller

javascript - CEFSharp RegisterExtension 不起作用

javascript - Angular - 在 ng-repeat 内添加赞成按钮