【发布时间】:2018-04-29 17:57:01
【问题描述】:
这是错误 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
});
});
});
【问题讨论】:
-
欢迎来到 StackOverflow,为了增加您获得体面答案的变化,请阅读:stackoverflow.com/help/how-to-ask
标签: node.js express sequelize.js