2014-07-21 56 views
1

我正在嘗試使用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'); 
+0

在使用它之前是否包含了'ember-validation'?看來'Ember.Validations'不存在。你輸入了嗎? –

+0

你得到的實際錯誤是什麼? – Dhaulagiri

回答

0

你導入庫?

假設你使用的是日燼-CLI:

// in Brocfile.js after importing ember.js 

app.import('vendor/path/to/ember-validations'); 
+0

我已更新問題。是的,我在ember-cli中也使用了ember-cli – Nininea

+0

我無法添加文件夾,只能導入文件 – Nininea

1

好像你可能會錯誤地導入燼,驗證,但事業的根源在於,你不導入混入到控制器文件。以下將起作用。

在你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 
}); 
相關問題