我是炭烬新手。谁能帮助我如何将选定的值作为参数传递给 Action 处理程序“onSelectEntityType”。我尝试了以下操作,并且能够触发该操作。

<select class="form-control" id="entityType" {{action 'onSelectEntityType' on='change'}} >
    <option value="">Select</option>
    {{#each model as |entityType|}}
    <option value="{{entityType.id}}">{{entityType.entityTypeName}}</option>
    {{/each}}
</select>

组件js文件
import Ember from 'ember';

export default Ember.Component.extend({
    actions: {
      onSelectEntityType(value) {
         console.log(value)
      }
    }
});

最佳答案

如果您使用的是Ember 1.13.3或更高版本,则可以执行以下操作:

<select class="form-control" id="entityType" onchange={{action 'onSelectEntityType' value="target.value"}} >
  <option value="">Select</option>
  {{#each model as |entityType|}}
    <option value="{{entityType.id}}">{{entityType.entityTypeName}}</option>
  {{/each}}
</select>

要获得比我能提供的更好的解释,请参阅:http://balinterdi.com/2015/08/29/how-to-do-a-select-dropdown-in-ember-20.html

10-01 14:46
查看更多