Node.js Sequelize Невозможно прочитать свойство foreach из nulll - PullRequest
0 голосов
/ 29 апреля 2018

ЭТО ОШИБКА Ошибка типа: C: \ users \ gaffer \ desktop \ 6-й семестр \ GafferCart \ views \ admin \ add_product.ejs: 22 * ​​1002 *

Выполнение (по умолчанию): счетчик SELECT (*) AS count ОТ Products КАК Product; Выполнение (по умолчанию): SELECT id, title, slug, desc, category, price, images ОТ Products AS Product LIMIT 1; Выполнение (по умолчанию): SELECT id, title, slug ОТ Categories AS Category ПРЕДЕЛ 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

>

Невозможно прочитать свойство '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
            });

        });
 });

1 Ответ

0 голосов
/ 29 апреля 2018

Ваш объект категории пуст, пожалуйста, утешите объект.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...