私はangularjs、nodejs、およびpostgresqlを使用するWebアプリケーションを開発しています。データベースには、在庫用とクライアント用の2つのテーブルがあります。私は両方のテーブルがfindAll関数を持っている私のルートフォルダ内のindex.jsファイルを結合しました。 index.jsにテーブルの2つの参照を置くと、一度に1つしか動作しません。ここでは両方のテーブルは、それがfindAllのを含んで使用するテンプレートです:誰も私が何をしようとしています何TypeError:未定義のプロパティ 'findAll'を読み取ることができません
exports.getobjects = function(req, res) {
models.Object.findAll().then(function(objectss){
res.json(objects);
});
};
行われていますか? UPDATE:あなたは間違ってあなたの輸出を行っている
/*
* GET home page.
*/
var models = require("../models");
exports.index = function(req, res) {
res.render('index', {
title : 'title'
});
};
/* clients */
exports.getclients = function(req, res) {
models.Client.findAll().then(function(clients){
res.json(clients);
});
};
exports.saveclients = function(req, res) {
models.Client.create({
name: req.body.name,
ssn: req.body.ssn,
dln: req.body.dln,
dls: req.body.dls,
zip: req.body.zip,
email: req.body.email,
notes: req.body.notes,
}).then(function(clients){
res.json(clients.dataValues);
}).catch(function(error){
console.log("ops: " + error);
res.status(500).json({ error: 'error' });
});
};
/*inventory*/
exports.getunits = function(req, res) {
models.Unit.findAll().then(function(units){
res.json(units);
});
};
exports.saveunits = function(req, res) {
models.Unit.create({
name: req.body.text,
quant: reg.body.quant
}).then(function(units){
res.json(units.dataValues);
}).catch(function(error){
console.log("ops: " + error);
res.status(500).json({ error: 'error' });
});
};
index.jsコードを含めることはできますか?私が拾ったことの1つは、オブジェクト(2 ss)がコールバックメソッドに渡されているが、定義されていないオブジェクト(1 s)にアクセスしていることです。 – RedJandal
申し訳ありませんが、私のコードではありません! –
あなたの輸出の構文は実際にはうまくいますが、私はindex.jsを投稿します。 'module'はグローバルで、' exports.foo = function(){} 'が有効です。あなたの復興コードからは、何が失敗しているかは完全には分かりません。あなたはいくつかの行にreproを減らすことができますし、実際のエラーを投稿していますか? –