【问题标题】:ember select: selection computed alias vs value computed aliasember select:选择计算别名与值计算别名
【发布时间】:2013-11-21 23:28:08
【问题描述】:

我想知道这是一个错误还是我只是错过了一些东西......

在 ember.Select 上,您可以将“选择”设置为计算的别名,它可以工作。

selection: Em.computed.alias('parentView.controller.test3')

您可以将 'valueBinding' 设置为路径并且它可以工作。

valueBinding: 'parentView.controller.test2'

但是您不能将“值”设置为计算的别名,这是行不通的。

value: Em.computed.alias('parentView.controller.test')

我已经包含了一个 jsfiddle,它在最新的 ember 上演示了这一点。我在这里错过了什么吗?我以为我读到视图中的绑定将被默默弃用,我一直在尝试使用 Em.computed.alias() 代替。

http://jsfiddle.net/3DzzZ/

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    这是因为Ember.Select 上的value 是一个计算属性,而您正在覆盖该计算属性,从而破坏了代码隐藏

    /**
    In single selection mode (when `multiple` is `false`), value can be used to
    get the current selection's value or set the selection by it's value.
    
    It is not currently supported in multiple selection mode.
    
    @property value
    @type String
    @default null
    */
    
    
    value: Ember.computed(function(key, value) {
      if (arguments.length === 2) { return value; }
      var valuePath = get(this, 'optionValuePath').replace(/^content\.?/, '');
      return valuePath ? get(this, 'selection.' + valuePath) : get(this, 'selection');
    }).property('selection'),
    

    selection 只是一个无聊的属性

     /**
    When `multiple` is `false`, the element of `content` that is currently
    selected, if any.
    
    When `multiple` is `true`, an array of such elements.
    
    @property selection
    @type Object or Array
    @default null
    */
    
    
    selection: null
    

    【讨论】:

    • value 不是在上面列出的代码中被调用或设置的函数,他实际上是在覆盖对象上的属性,在他的第三个麻烦示例中,它永远不会触及默认实现。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-11
    • 1970-01-01
    相关资源
    最近更新 更多