在Ember中使用车把选择语句

时间:2018-10-17 10:21:57

标签: ember.js

/考试/ template.hbs

<form>
  <select name="selectvalue" id="selectvalue">
     <option value="one"> One </option>
     <option value="two"> Two </option>
     <option value="three"> Three </option>
  </select>
  <button type="submit" {{action "printans"}}> Submit </button>
</form>

/考试/ controller.hbs

import Controller from '@ember/controller';
export default Controller.extend({
    actions: {
        printans: function(){
            let val = this.get('selectvalue');
            console.log(val);
        }
    }
});

我需要做的是用把手替换template.hbs中的html代码,并在提交表单时将值传递给控制器​​。

1 个答案:

答案 0 :(得分:1)

您的意思是:

<form>
    {{#power-select
      selected=selectvalue
      options=cities
      onchange=(action "printans")
      as |name|
    }}
      {{name}}

    {{/power-select}}
</form>

我完全在猜测。
其他详细信息将有所帮助:  -您打算做什么(特别是)  -您从哪里获得物品清单?

有这个插件,它涵盖了许多常见的行为:https://github.com/cibernox/ember-power-select

相关问题