Javascript 如何从hbs中按id选择元素
我使用这行代码使用ember.js添加了一个select标记Javascript 如何从hbs中按id选择元素,javascript,ember.js,handlebars.js,Javascript,Ember.js,Handlebars.js,我使用这行代码使用ember.js添加了一个select标记 {{view Ember.Select contentBinding = "content"}} 后来,我有一个按钮,它调用同一控制器中的一个函数,我想知道如何从这个select标记中获取所选选项 注意:其id为“ember240” 经过一些调查,我发现最好的解决方案是在控制器中声明如下内容: selectedoption : null, 然后像这样使用选择绑定 {{view Ember.Select contentBinding
{{view Ember.Select contentBinding = "content"}}
后来,我有一个按钮,它调用同一控制器中的一个函数,我想知道如何从这个select标记中获取所选选项
注意:其id为“ember240” 经过一些调查,我发现最好的解决方案是在控制器中声明如下内容:
selectedoption : null,
然后像这样使用选择绑定
{{view Ember.Select contentBinding = "content"
selectionBinding = selectedoption}}
有关此问题的详细信息,请参阅。官方方法是使用
值
属性:
{{view Ember.Select
content=programmers
optionValuePath="content.id"
optionLabelPath="content.firstName"
value=currentProgrammerId}}
这将使用optionValuePath
将所选值绑定到value
中给定的属性。在这种情况下,控制器中的属性currentProgrammerId
将设置为所选程序员的id
属性
元素将使用firstName
属性呈现
示例程序员数组如下所示:
programmers: [
{id: 1, firstName: "Pete"},
{id: 2, firstName: "Julia"},
{id: 8, firstName: "Jessy"},
{id: 22, firstName: "Hank"},
]
参考:请提供更多上下文。selectionBinding不再存在(至少在1.7中)。它现在被称为“价值”。有关详细信息,请参见我的答案:)