我试图使用余烬验证。我在我的控制器中添加了validation.mixin,但它会导致错误。这是我的控制器代码:
var loanController = Ember.ObjectController.extend(Ember.Validations.Mixin);
loanController.reopen({
borrowingLimits:null,
industries:null,
actions:{
submitAction:function(){
var model=this.get('model');
if (model!=null) {
var controller = this;
$.ajax({
type :'post',
async:false,
url : '/api/v1/loanapplication/',
data: JSON.stringify(model),
contentType: "application/json; charset=utf-8"
}).done(function (data) {
controller.transitionToRoute('upload-documents',data);
});
}
}
},
validations: {
applicantFirstName: {
presence: true,
length: { minimum: 5 }
}
}
});
export default loanController;
我该如何解决这个问题?
更新 我添加了进口
app.import('vendor/ember-validations/packages/ember-validations/lib/core.js');
app.import('vendor/ember-validations/packages/ember-validations/lib/defaultMessages.js');
app.import('vendor/ember-validations/packages/ember-validations/lib/errors.js');
app.import('vendor/ember-validations/packages/ember-validations/lib/main.js');
app.import('vendor/ember-validations/packages/ember-validations/lib/mixin.js');
app.import('vendor/ember-validations/packages/ember-validations/lib/validatorNamespaces.js');
app.import('vendor/ember-validations/packages/ember-validations/lib/validators.js');
答案 0 :(得分:1)
您似乎可能错误地导入了ember-validations,但原因的根源是您没有将mixin导入控制器文件。以下将有效。
在Bower.json
文件中
{
"name": "app-name",
"dependencies": {
"ember-validations": "http://builds.dockyard.com.s3.amazonaws.com/ember-validations/ember-validations-latest.min.js",
}
}
运行bower install
。
在Brofile.js
:
app.import('vendor/ember-validations/index.js');
mixins/form-saving.js
:
export default Em.Mixin.create(
Em.Validations.Mixin, {
// Your common form saving functions and properties
});
controllers/loan.js
:
import FormSaving from 'app-name/mixins/form-saving';
export default Em.ObjectController.extend(
FormSaving, {
// Methods and Properties here
});
答案 1 :(得分:0)
您导入了库吗?
假设您使用的是ember-cli:
// in Brocfile.js after importing ember.js
app.import('vendor/path/to/ember-validations');