[英]MongoDB - Can't read data from the database
hi I am a newbie and am facing an issue.I am doing a rideshare cab application and am getting Cannot read property 'length' of undefined error
in jade file. 嗨,我是新手,正在遇到问题。我正在做一个rideshare cab应用程序,并且得到了
Cannot read property 'length' of undefined error
jade文件Cannot read property 'length' of undefined error
。
My jade file is as follows:- 我的玉器档案如下:
html
body
h1 Passengers List
each user in users
script(type='text/javascript').
function checkboxlimit(checkgroup, limit){
var checkgroup=checkgroup
var limit=limit
for (var i=0; i<checkgroup.length; i++){
checkgroup[i].onclick=function(){
var checkedcount=0
for (var i=0; i<checkgroup.length; i++)
checkedcount+=(checkgroup[i].checked)? 1 : 0
if (checkedcount>limit){
this.checked=false
}
}
}
}
p Select your 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 this file i am trying to display all the users and let the driver select four passengers.. 在此文件中,我试图显示所有用户,并让驾驶员选择四名乘客。
Once done I will create a new jade file to display the driver and the passenger associated with the driver 完成后,我将创建一个新的玉文件来显示驾驶员和与驾驶员相关的乘客
The following is my serverjs snippet:- 以下是我的serverjs代码段:-
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 is as 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 to understand what is wrong in the code..Please help me out 我似乎无法理解代码中的错误。请帮助我
Thanks 谢谢
var x = {};
x.someProperty; //this is undefined
x.someProperty.length; // Cannot read property 'length' of undefined
So, you are trying to get the property of an undefined. 因此,您正在尝试获取未定义的属性。 Try to find in which part of the code you are trying to get
length
. 尝试找到要获取
length
的代码的哪一部分。
function checkboxlimit(checkgroup, limit) {
pay attention to this line, checkgroup its undefined
. function checkboxlimit(checkgroup, limit) {
注意这一行,checkgroup它的undefined
。
And this var checkgroup=checkgroup
, var limit=limit
is pointless. 而且这个
var checkgroup=checkgroup
, var limit=limit
是没有意义的。
=) =)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.