【问题标题】:Ember simple array to display in componentEmber 简单数组显示在组件中
【发布时间】:2016-07-12 02:07:23
【问题描述】:

组件中的简单数组,它将显示在选择器标签中。我无法让它工作。 firstSelector 不显示任何内容。

在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(),

在component.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'),

我怎样才能像其他方式(作为函数)那样编写它

【问题讨论】:

    标签: javascript ember.js components selector


    【解决方案1】:

    我不确定你的设置中的所有内容,但我注意到的一件事是,如果你希望你的computed property 根据对selectors 的更改来触发,你会想要这样的东西。

      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');
      })
    

    【讨论】:

    • 谢谢,这就是我要找的东西!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-08
    • 2023-03-16
    • 2017-04-10
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 2018-07-16
    相关资源
    最近更新 更多