TypeError:arr [idx]不是函数

时间:2018-06-05 06:41:29

标签: node.js

var validate = require('validate-fields')();
var series = require('async-series');


exports.calculateGstBaseOnInput = function(req, res,next) {
    for(var item of req.body.so_items) {
        req.productid = item.productid;
        req.qty = item.qty;
        series([
            getitemdetail(null,req,res),
        ], function (error, success) {
            res.json({error : error, success : success});
        });
     }
    res.json({status : 'gst', statusMessage : 'gst success'});

}

getitemdetail =function(req,res)
{
    console.log(req.productid);
    console.log(req.qty);

}

错误:

  

2222 5 TypeError:arr [idx]不是函数       at handleItem(D:\ node \ node_modules \ async-series \ index.js:14:13)       在系列(D:\ node \ node_modules \ async-series \ index.js:30:3)       在exports.calculateGstBaseOnInput(D:\ node \ app \ addorder.js:48:9)       在Layer.handle [as handle_request](D:\ node \ node_modules \ express \ lib \ router \ layer.js:95:5)       在下一个(D:\ node \ node_modules \ express \ lib \ router \ route.js:137:13)       在Query._callback(D:\ node \ app \ addorder.js:40:21)       在Query.Sequence.end(D:\ node \ node_modules \ mysql \ lib \ protocol \ sequences \ Sequence.js:88:24)       在Query._handleFinalResultPacket(D:\ node \ node_modules \ mysql \ lib \ protocol \ sequences \ Query.js:139:8)       在Query.EofPacket(D:\ node \ node_modules \ mysql \ lib \ protocol \ sequences \ Query.js:123:8)       在Protocol._parsePacket(D:\ node \ node_modules \ mysql \ lib \ protocol \ Protocol.js:279:23)

1 个答案:

答案 0 :(得分:1)

series除了一个函数数组,请尝试更改下面的代码

exports.calculateGstBaseOnInput = function(req, res,next) {
  for(var item of req.body.so_items) {
    req.productid = item.productid;
    req.qty = item.qty;
    series([function(done){
      getitemdetail(null,req,res);
      done();
    }], function (error, success) {
        res.json({error : error, success : success});
    });
  }
  res.json({status : 'gst', statusMessage : 'gst success'});
}

有关详细信息,请参阅 - https://www.npmjs.com/package/async-series#user-content-usage