繁体   English   中英

MongoDB-无法从数据库读取数据

[英]MongoDB - Can't read data from the database

嗨,我是新手,正在遇到问题。我正在做一个rideshare cab应用程序,并且得到了Cannot read property 'length' of undefined error jade文件Cannot read property 'length' of undefined error

我的玉器档案如下:

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)

在此文件中,我试图显示所有用户,并让驾驶员选择四名乘客。

完成后,我将创建一个新的玉文件来显示驾驶员和与驾驶员相关的乘客

以下是我的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');
    });

我的模型如下:

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
});

我似乎无法理解代码中的错误。请帮助我

谢谢

var x = {};
x.someProperty; //this is undefined
x.someProperty.length; // Cannot read property 'length' of undefined

因此,您正在尝试获取未定义的属性。 尝试找到要获取length的代码的哪一部分。

function checkboxlimit(checkgroup, limit) {注意这一行,checkgroup它的undefined

而且这个var checkgroup=checkgroupvar limit=limit是没有意义的。

=)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM