javascript - MongoDB - Can't read data from the database -
hi newbie , facing issue.i doing rideshare cab application , getting cannot read property 'length' of undefined error in jade file.
my jade file follows:-
html body h1 passengers list each user in users script(type='text/javascript'). function checkboxlimit(checkgroup, limit){ var checkgroup=checkgroup var limit=limit (var i=0; i<checkgroup.length; i++){ checkgroup[i].onclick=function(){ var checkedcount=0 (var i=0; i<checkgroup.length; i++) checkedcount+=(checkgroup[i].checked)? 1 : 0 if (checkedcount>limit){ this.checked=false } } } } p select passenger below: form#world(name='man') input(type='checkbox', name='dude') | li {passenger.name} br script(type='text/javascript'). //syntax: checkboxlimit(checkbox_reference, limit) checkboxlimit(document.forms.man.dude, 4) in file trying display users , let driver select 4 passengers..
once done create new jade file display driver , passenger associated driver
the following serverjs snippet:-
app.post('/passenger',function(req,res){ var user = new user({profile:{name:req.body.uname}, type:"passenger", phone_no:req.body.contact, origin:{city:req.body.pick}, destination:{city:req.body.drop} // email:req.body.email, // password:req.body.password }) user.save(); // passengers.push(user) // console.log(passengers) res.render('checkbox', {user: user}); // res.redirect('/checkbox') }); app.get('/checkbox',function(req,res){ res.render('checkbox'); }); my model follows:-
var userschema = new mongoose.schema({ email: { type: string, unique: true, lowercase: true }, password: string, facebook: string, google: string, origin: {city: string, state: string}, destination: {city: string, state: string}, price: array, time: date, phone_no: string, accepted:string, tokens: array, type: string, profile: { name: { type: string, default: '' }, gender: { type: string, default: '' }, location: { type: string, default: '' }, website: { type: string, default: '' }, picture: { type: string, default: '' } }, resetpasswordtoken: string, resetpasswordexpires: date }); i cant seem understand wrong in code..please me out
thanks
var x = {}; x.someproperty; //this undefined x.someproperty.length; // cannot read property 'length' of undefined so, trying property of undefined. try find in part of code trying length.
function checkboxlimit(checkgroup, limit) { pay attention line, checkgroup undefined.
and var checkgroup=checkgroup, var limit=limit pointless.
=)
Comments
Post a Comment