我有个东西
let StatusDescriptions = {
'A' : 'Available' ,
'W' : 'Waitlisted' ,
'C' : 'Closed'
};它可以在页面中找到。我用把手来显示页面。我可以在这样的select-2标签中使用这个对象吗?我试着把optionValuePath作为'key‘'id’等,我知道这是愚蠢的。我也是安博的新手。请帮帮忙。
{{select-2 id="myID" content=StatusDescriptions optionLabelPath="what should be here" placeholder='Choose Status' searchEnabled=false}}发布于 2016-04-13 07:13:05
更新:如果您已经安装了选择2 Ember .(如否,请参阅以下指示)
您的对象应该如下所示:
statusDescriptions: [
{
id: 'A',
text: 'Available'
},
{
id: 'W',
text: 'Waitlisted'
},
{
id: 'C',
text: 'Closed'
}
]所以你可以把这个放在车把上:
{{select-2
content=statusDescriptions
id=id
value=selectedChoice
searchEnabled=false
}}在您的车把或控制器中,您可以观察或在计算属性中使用selectedChoice属性。(这可能在您的车把文件中:)
Selected: {{selectedChoice.id}} - {{selectedChoice.text}}Update2:如果您真的想使用一个简单的对象,可以使用计算的属性来转换它。例如,这可能在您的控制器中:
import Ember from 'ember';
export default Ember.Controller.extend({
statusDescriptions: {
'A' : 'Available',
'W' : 'Waitlisted',
'C' : 'Closed'
},
statusForSelect: Ember.computed('statusDescriptions', function() {
const statusDescriptions = this.get('statusDescriptions');
return Object.keys(statusDescriptions).map(key =>
Object.create({id: key, text: statusDescriptions[key]})
);
})
});因此,在模板中,可以使用statusForSelect作为content。
{{select-2
content=statusForSelect
id=id
value=selectedChoice
searchEnabled=false
}}如果您尚未安装Select2Addon:
是的,你可以在Ember项目中使用Select2,但是你必须安装一个特定的Ember插件。您最喜欢的javascript库大部分已经移植到Ember,您可以在这里查看一下:http://www.emberobserver.com
您可以在这里找到关于Select:https://www.emberobserver.com/categories/select的列表
正如你所看到的,有一个ember-select-2加号。在项目文件夹中运行:
ember install ember-select-2如果您想使用这个包,请按照说明执行:https://github.com/iStefo/ember-select-2
然而,有更多最新的选择包,你可以尝试他们。其中最受欢迎的是:http://www.ember-power-select.com/
https://stackoverflow.com/questions/36588368
复制相似问题