繁体   English   中英

Ember JS,将输入标签值作为参数传递给操作把手

[英]Ember JS,Pass input tag value as parameter in action handlbars

我想从<input>标记获取值并将其作为参数传递给EmberJS中的操作

当我使用JQuery {{action 'add' this.$('#x').val()}} action'add'this {{action 'add' this.$('#x').val()}} Ember无法建立并parse error on line ...给出parse error on line ...

在这里,我想将x和y作为参数传递给{{action}} ,我知道发送参数的语法是{{action parameter1 parameter2 ..etc}}

模板\\ alpha.hbs

<h1>alpha template</h1>
<div>
 <label>X value</label>
 <input type="text" id="x">
 <label>Y</label>
 <input type="text" id="y">
 <input type="button" id ="add-button" value="Add" {{action 'add' }}>
</div>

控制器\\ alpha.js

import Ember from 'ember';

export default Ember.Controller.extend({
  actions:{
    add: function(x, y){
      alert('this is done right '+x+ ' ' + y);
    }
  }
});

我在不传递参数的情况下测试了代码,并且代码按预期方式工作,给出了所需的警报

您需要利用Ember中的input助手和值绑定:

<br><h1>alpha template</h1>
<div>
 <label>X value</label>
 {{input value=xValue}}
 <label>Y</label>
 {{input value=yValue}}
 <input type="button" id ="add-button" value="Add" {{action 'add' xValue yValue}}/>
</div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM