2017-03-06 91 views
0

它給了我這個問題 - 類型錯誤:Course.createCourse不是一個函數 從這個代碼:不是一個函數錯誤

Course.createCourse(newCourse, function (err, course) { 
     if (err) throw err; 
     console.log(course); 
    }); 

我知道它的一點信息,但有人可以幫助我嗎?如果您需要更多的代碼,我將提交

+2

課程對象不具有的功能 'createCourse'。確保它在對象上定義。 –

+0

錯誤消息告訴你的問題是什麼?你做了什麼,找出原因createCourse不存在?你檢查了它的來源嗎? –

回答

0

課程是你的模型,你在你的控制器有進口和它沒有任何功能與這樣的名字在你的模型這就是爲什麼你得到這個錯誤。

controller.js

Course.createCourse(newCourse, function (err, course) { 
    if (err) throw err; 
    console.log(course); 
}); 

model.js

Course.statics.createCourse = function(newCourse, callback){ 
    // your query will come here to create the course you want for example 
    this.create(newCourse, callback); 
}); 
+0

非常感謝,你真的救了我:) – Behaa

相關問題