如何在路由器中修复“ cb不是功能”?

时间:2018-12-30 22:35:58

标签: reactjs callback router

我要在路由器的当前查询中添加另一个参数。
但我收到此错误:

  

TypeError:cb不是函数
  在Query.client.query [作为回调]

这是我的代码:

    // old code with just distance params that works
    ...
    const express = require('express');
    const pool = require('../modules/pool');
    const router = express.Router();

    router.get('/:lat/:lon', (req, res) => {
        console.log('location GET local route');

    let queryText = `SELECT *, distance($1, $2, location.latitude, location.longitude) as distance FROM location ORDER BY distance ;`
    pool.query(queryText, [req.params.lat, req.params.lon]).then((result) => {
        res.send(result.rows);
        // console.log(result.rows)
    }).catch((error) => {
        console.log(error);
        res.sendStatus(500);
    });
});
    module.exports = router;

    // this is the current router with the error.
    const express = require('express');
    const pool = require('../modules/pool');
    const router = express.Router();

    router.get('/:lat/:lon/:type', (req, res) => {
    console.log('location GET local route');

    let queryText = `SELECT *, distance($1, $2, location.latitude, location.longitude) as distance FROM location ORDER BY distance WHERE "type" = $1;;`
    pool.query(queryText, [req.params.lat, req.params.lon], [req.params.type])// erroring here 
    .then((result) => {
        res.send(result.rows);
        // console.log(result.rows)
    }).catch((error) => {
        console.log(error);
        res.sendStatus(500);
    });
});
module.exports = router;

1 个答案:

答案 0 :(得分:0)

尝试更改

pool.query(queryText, [req.params.lat, req.params.lon], [req.params.type])

pool.query(queryText, [req.params.lat, req.params.lon, req.params.type])