我在 ember js 应用程序中使用 ember-cp-validation 进行验证。在组件页面中使用 validate() 方法。但我收到错误(验证不是函数)。我提到了这个链接
在模型页面(profile.js)中,
import DS from 'ember-data';
import { validator, buildValidations } from 'ember-cp-validations';
const Validations = buildValidations({
name: validator('presence', true),
address:[
validator('presence', true),
validator('length', { max: 300}),
],
pincode: validator('presence', true),
email:[
validator('presence', true),
validator('format', {type:'email'})
]
});
export default DS.Model.extend(Validations,{
name: DS.attr('string'),
address: DS.attr('string'),
pincode: DS.attr('number'),
email: DS.attr('string')
});
和组件页面,
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
authenticate() {
let profile = this.get('profile');
profile.validate().then(({ validations }) => {
if(validations.get('isValid')){
this.transitionToRoute("welcome");
}
});
}
}
});