组件中的简单数组,它将显示在选择器标签中。我无法让它发挥作用。第一个选择器不显示任何内容。
在 component.js 中:
sortPropertiesAsc: ['value:asc'],
selectors: ['model.modelObjects', 'model.location'],
firstSelector: function(){
const firstGroupObjects = this.get('selectors')[0];
return Ember.computed.sort(firstGroupObjects, 'sortPropertiesAsc');
}.property(),
在组件.hbs中
<select onchange={{ action 'selectBrand' value="target.value" }}>
<option value="" >Select company</option>
{{#each firstSelector as |company|}}
<option value={{company.id}} selected={{eq brand company.id}}> {{company.value}}</option>
{{/each}}
</select>
如果我在 component.hbs 中像这样编写firstSelector,它将起作用:
firstSelector: Ember.computed.sort('model.modelObjects', 'sortPropertiesAsc'),
我怎样才能像其他方式一样编写它(作为函数)
最佳答案
我不确定你的设置中所有的内容都在起作用,但我立即注意到的一件事是,如果你想要你的 computed property要根据选择器
的更改触发,您需要这样的东西。
firstSelector: Ember.computed('selectors', function() {
const firstGroupObjects = this.get('selectors.firstObject');
return Ember.computed.sort(firstGroupObjects, 'sortPropertiesAsc');
})
如果 sortPropertiesAsc
更改了您也想添加的值
firstSelector: Ember.computed('selectors', 'sortPropertiesAsc', function() {
const firstGroupObjects = this.get('selectors.firstObject');
return Ember.computed.sort(firstGroupObjects, 'sortPropertiesAsc');
})
关于javascript - 在组件中显示的 Ember 简单数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36200948/