“无法在发送标题后设置标题”抛出错误但没有双重回调

时间:2013-05-04 03:19:56

标签: node.js express

我的代码分为两个文件:router.jswork.js

以下是work.js的代码:

getThumbnailItems = function(callback, res) {
        fs.readdir(this.thumbnailPath, function(err, files) {

                callback(files, res);
            }
        });
    }

以下是router.js中调用方法的地方:

exports.home = function(req, res) {
    getThumbnailItems(function(items) {
        console.log(items);
        if (res) {
            res.render("home", {title: "The Work Speaks For Itself", items: items});
        }
    }, res)

}

我在getThumbnails中使用回调来呈现home视图。但是错误"Can't set headers after they are sent"不断被抛出。有谁知道这里发生了什么?

0 个答案:

没有答案