簡體   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