1

I'm building a nodejs server for my mobile app and I've got a problem when I save data I can show it in my data.jade

Here my error message :

Cannot read property '0' of undefined
    at jade_debug.unshift.lineno (eval at <anonymous> (/Users/****/Documents/Node-    server/node_modules/jade/lib/jade.js:160:8), <anonymous>:33:21)
at eval (eval at <anonymous> (/Users/****/Documents/Node-server/node_modules/jade/lib/jade.js:160:8), <anonymous>:65:4)
at res (/Users/****/Documents/Node-server/node_modules/jade/lib/jade.js:161:38)
at Object.exports.render (/Users/****/Documents/Node-server/node_modules/jade/lib/jade.js:257:10)
at Object.exports.renderFile (/Users/****/Documents/Node-server/node_modules/jade/lib/jade.js:293:18)
at View.exports.renderFile [as engine] (/Users/Yanis/Documents/Node-server/node_modules/jade/lib/jade.js:278:21)
at View.render (/Users/****/Documents/Node-server/node_modules/express/lib/view.js:76:8)
at Function.app.render (/Users/****/Documents/Node-server/node_modules/express/lib/application.js:505:10)
at ServerResponse.res.render (/Users/****/Documents/Node-server/node_modules/express/lib/response.js:756:7)
at /Users/****/Documents/Node-server/index.js:44:9

index.js :

app.get('/:collection', function(req, res) {
    var params = req.params;
    collectionDriver.findAll(req.params.collection, function (error, objs) {
        if (error) {
            console.log("mongo db error"+error);
            objs = [];
        }
        else {
            if (req.accepts('html')) {
                res.render('data', {objects: objs, collection: req.params.collection});
            }
            else {
                res.set('Content-Type', 'application/json');
                res.send(200, objs);
            }
       }
   });
});

and finally my data.jade :

#objects
    table(border=1)
            if objects.length > 0
                - each val, key in object[0]
                    th= key
            - each obj in objects
                tr.obj
                - each val, key in obj
                    td.key= val

As you can see my object is not "define" in the data.jade and I don't know why. I don't know if the problem come from the jade file or de .js. Anyone of you have a solution?

1 Answer 1

2

object[0] should probably be objects[0] in your data.jade.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.