gpt4 book ai didi

Node.js Sequelize 无法读取 nulll 的属性

转载 作者:行者123 更新时间:2023-12-03 22:40:00 25 4
gpt4 key购买 nike

这是错误
TypeError: C:\users\gaffer\desktop\6th Semester\GafferCart\views\admin\add_product.ejs:22


执行(默认):SELECT count(*) AS count FROM Products AS Product ;
执行(默认): SELECT id , title , slug , desc , category , price , images FROM Products AS Product LIMIT 1;
执行(默认): SELECT id , title , slug FROM Categories AS Category LIMIT 1;

    20|         <label for="">Category</label>

21| <select name="category" class="form-control">

>> 22| <% categories.forEach(function(cat){ %>

23| <option value="<%= cat.slug %>"><%= cat.title %
</option>
24| <% }); %>
25| </select

>

无法读取 null 的属性“forEach”
          // Get Product model
var Product = require('../models/product');

// Get Product model
var Category = require('../models/category');

/*
* Get products index
*/

router.get('/',function(req,res){

var count;

models.Product.count(function(c){
count=c;
})
//models.product.find
models.Product.find({
attributes:
['id','title','slug','desc','category','price','images']
})
.then(function(products){
res.render('admin/products',{
products:products,
count:count
});
});
});

/*
* GET add product
*/
router.get('/add-product', function (req, res) {

var title = "";
var desc = "";
var price = "";

models.Category.find({
attributes:['id','title','slug']
})
//.then((categories)=>{ both are giving same errors

.then(function(categories){
res.render('admin/add_product', {
title: title,
desc: desc,
categories: categories,
price: price
});

});
});

最佳答案

您的类别对象为空,请控制对象。

关于Node.js Sequelize 无法读取 nulll 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50089645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com