我试图验证email
地址,并相应地启用或禁用操作按钮。但它不起作用。我对emberjs
非常陌生,请帮助我吗? Here is my TutorialEmber无法通过验证电子邮件来启用/禁用
HTML代码(HBS):
<div class="jumbotron text-center">
<h1>Coming Soon</h1>
<br/><br/>
<p>Don't miss our launch date, request an invitation now.</p>
<div class="form-horizontal form-group form-group-lg row">
<div class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-1 col-md-5 col-md-offset-2">
<input type="email" value=emailAddress class="form-control" placeholder="Please type your e-mail address." autofocus="autofocus"/>
</div>
<div class="col-xs-10 col-xs-offset-1 col-sm-offset-0 col-sm-4 col-md-3">
<button class="btn btn-primary btn-lg btn-block" disabled={{isDisabled}} {{action 'saveInvitation'}}>Request invitation</button>
</div>
</div>
<br/><br/>
</div>
控制器JS:
import Ember from 'ember';
export default Ember.Controller.extend({
emailAddress:'',
isValid: Ember.computed.match('emailAddress', /^[email protected]+\..+$/),
isDisabled: Ember.computed.not('isValid'),
actualEmailAddress: Ember.computed('emailAddress', function() {
console.log('actualEmailAddress function is called: ', this.get('emailAddress'));
}),
emailAddressChanged: Ember.observer('emailAddress', function() {
console.log('observer is called', this.get('emailAddress'));
}),
actions: {
saveInvitation() {
alert(`Saving of the following email address is in progress: ${this.get('emailAddress')}`);
this.set('responseMessage', `Thank you! We've just saved your email address: ${this.get('emailAddress')}`);
this.set('emailAddress', '');
}
}
});
当我输入有效电子邮件,按钮不能够! 在此先感谢。
UPDATE:
在浏览器中我得到这个错误:
DEPRECATION: Usage of `router` is deprecated, use `_routerMicrolib` instead.
感谢您的详细信息。我今天刚刚开始了'余烬'。我正在关注这个教程。 – 3gwebtrain
很棒;用余烬玩得开心:) – alptugd
我刚开始学习Ember。你能推荐一些好的教程吗? – 3gwebtrain