olarak geçiş fonksiyonu Bu sınıf benim expressjs uygulama içinde tüm denetleyicileri uzatmak için kullanılır: Eğer ben yapmış otomatik kurulum için bir "kayıt" yöntemi de görebileceğiniz gibiES6 Sınıf parametre
import response from '../utils/responseParser.js';
const APISLUG = '/api/v1/';
export default class BaseController {
constructor(name, app, model){
this.model = model;
this.app = app;
this.name = name;
console.log(model);
this.register();
}
register() {
this.app.get(APISLUG + this.name, this.all);
}
/*
Retrive all records
*/
all(req, res, next) {
this.model.all(req.body, (err, data) => {
if(err) return res.json(response.replyError(data));
return res.json(response.reply(data));
});
}
}
tüm temel yollar.
bu hat üzerinde bir hata unable to read property " model " of undefined "
olsun:
this.app.get(APISLUG + this.name, this.all);
Biliyorum bu parametre olarak işlev geçerken kapsamı kaybolmak olmasından kaynaklanmaktadır olduğuna inanıyoruz. Bunu Nasıl Çözebilirim?
Teşekkür ederiz! işe yarıyor. –
Rica ederim :) –
'.bind (this)' sihirli, teşekkür ederim! – Robula