我正在嘗試使用ember-validation。我在我的控制器中添加了validation.mixin,但它導致錯誤。這是我的控制器代碼:TypeError:無法讀取未定義屬性'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');
在使用它之前是否包含了'ember-validation'?看來'Ember.Validations'不存在。你輸入了嗎? –
你得到的實際錯誤是什麼? – Dhaulagiri