簡體   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