ember 路线中的表格 returns 未定义
ember form in route returns undefined
我是 Ember 的新手。当我单击提交时,控制台显示 this.getProperties 正在为电子邮件和密码输入返回未定义。我不确定这里缺少什么。登录是一条路线。
login.hbs:
<div class="login">
<div class="login-info">
<b>LOGIN TO PROCEED.</b>
</div>
<div class="form">
<form {{action 'authenticate'}} on='submit'>
<label for="email"><small>EMAIL</small></label>
<br>
{{input value=email placeholder='Enter Email' class='form-control' type='text'}}
<br>
<label for="password"><small>PASSWORD</small></label>
<br>
{{input value=password placeholder='Enter Password' class='form-control' type='password'}}
<br>
<div class="login-button">
<button type="submit">
Login
</button>
</div>
</form>
</div>
</div>
login.js
import Ember from 'ember';
export default Ember.Route.extend({
session: Ember.inject.service('session'),
actions: {
authenticate() {
let {email, password} = this.getProperties('email','password');
Ember.Logger.info("email: ",email," password: ",password);\this shows undefined for both email and password
this.get('session').authenticate('authenticator:oauth2', email, password).then(() => {
Ember.Logger.info("login successful");
}, (err) => {
Ember.Logger.info("login unsuccessful. message: ",err.errors);
});
}
}
});
您在模板中使用的属性实际上是控制器的一部分,而不是路由。因此,如果您尝试在路线中记录 this.controller.get('email)
,您应该能够获得正确的值。
我是 Ember 的新手。当我单击提交时,控制台显示 this.getProperties 正在为电子邮件和密码输入返回未定义。我不确定这里缺少什么。登录是一条路线。
login.hbs:
<div class="login">
<div class="login-info">
<b>LOGIN TO PROCEED.</b>
</div>
<div class="form">
<form {{action 'authenticate'}} on='submit'>
<label for="email"><small>EMAIL</small></label>
<br>
{{input value=email placeholder='Enter Email' class='form-control' type='text'}}
<br>
<label for="password"><small>PASSWORD</small></label>
<br>
{{input value=password placeholder='Enter Password' class='form-control' type='password'}}
<br>
<div class="login-button">
<button type="submit">
Login
</button>
</div>
</form>
</div>
</div>
login.js
import Ember from 'ember';
export default Ember.Route.extend({
session: Ember.inject.service('session'),
actions: {
authenticate() {
let {email, password} = this.getProperties('email','password');
Ember.Logger.info("email: ",email," password: ",password);\this shows undefined for both email and password
this.get('session').authenticate('authenticator:oauth2', email, password).then(() => {
Ember.Logger.info("login successful");
}, (err) => {
Ember.Logger.info("login unsuccessful. message: ",err.errors);
});
}
}
});
您在模板中使用的属性实际上是控制器的一部分,而不是路由。因此,如果您尝试在路线中记录 this.controller.get('email)
,您应该能够获得正确的值。