繁体   English   中英

Ember.js如何访问从Ember.Select中选择的整个对象?

[英]Ember.js How to access the whole object selected from Ember.Select?

我的控制器中的选择选项具有以下内容:

opts: [
    {id: 1, code: 'TEST A', desc: 'DESC A', other: 'EXAMPLE A'},
    {id: 2, code: 'TEST B', desc: 'DESC B', other: 'EXAMPLE B'},
    {id: 3, code: 'TEST C', desc: 'DESC C', other: 'EXAMPLE C'}
],
v: 2,

这是在我的application.hbs中

{{view Ember.Select
    content=opts
    optionValuePath='content.id',
    optionLabelPath='content.code'
    value=v}}

这将使select元素具有“ TEST B被预选。

每当我从列表中选择一个值时,如何获取整个对象? 我知道我可以通过this.get('v')获得值,该值返回select元素的值。 有没有办法在所选对象中获取其他属性?

请帮忙。

您可以绑定到使对象本身具有选择的选择

{{view Ember.Select
    content=opts
    optionValuePath='content.id'
    optionLabelPath='content.code'
    value=v
    selection=foo}}

this.get('foo');

this.get('foo.id');

示例: http//emberjs.jsbin.com/quhov/1/edit

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM