如何将包含猫鼬模式的猫鼬模块集合存储在对象数组中?

时间:2019-07-09 06:43:41

标签: javascript arrays node.js object mongoose

我目前正在使用mongo,express和node进行此项目,而我对这些完全陌生。 我有一些包含存储在变量中的猫鼬模式的模块。然后我想创建一个对象数组,每个对象的值都等于该变量名。 如何访问那些对象的值,然后将其视为模式?因为我当前的代码始终在浏览器中返回“ TypeError:#不是函数”。

起初,我将键对象上的每个值都分配为一个字符串,但这没有用,然后我意识到自己犯了一个错误,然后我删除了引号,但那也没有用< / p>

// =============== Modules =============
const bbrc      = require('./models/backbone_rc_model'),
      bbrp      = require('./models/backbone_rp_model'),
      bbip      = require('./models/bbip_model'),
      gamas     = require('./models/gamas_model'),
      gamasFeeder       = require('./models/gamas_feeder_model'),
      gamasGaul         = require('./models/gamas_gaul_model'),
      gamasOdcodp       = require('./models/gamas_odc_odp_model'),
      gamasSekunder     = require('./models/gamas_sekunder_model'),
      metroRc           = require('./models/metro_rc_model'),
      metroRp           = require('./models/metro_rp_model'),
      predictiveMetro   = require('./models/predictive_metro_model')
      //each of the aboves have their own page showing different tables from 
      //collections in database
// =====================================

// ============ Tables Object ==========
var tablesObj = 
    [
        {backbone_rc: bbrc},
        {backbone_rp: bbrp},
        {bb_ip_terra: bbip},
        {gamas      : gamas},
        {gamas_feeder: gamasFeeder},
        {gamas_gaul: gamasGaul},
        {gamas_odc_odp: gamasOdcodp},
        {gamas_sekunder: gamasSekunder},
        {metro_rc: metroRc},
        {metro_rp: metroRp},
        {predictive_metro: predictiveMetro}
    ]
// =====================================

// 0000000000000 EDIT Content Sub Menu 0000000000000000000
// each of table page has "Edit" button that will render 'edit_content' ejs //file

app.get('/:table/edit', (req, res) => {
    var skema = req.params.table
    tablesObj.forEach(function(item){
        if(skema == (Object.keys(item)).toString()){
            skema = Object.values(item)
            return skema
        }
    })

    skema.find({}, (err, items) => {
        if(err){
            console.log('Not found')
        }
        else{
            res.render('edit_content', {items: items})
        }
    })
})

我期望skema.find({},(err,item)=> {...})每次在任何:tables页面上按下“编辑”按钮时都会自动呈现edit_content页面。

希望您能解决这个问题,谢谢

0 个答案:

没有答案