带有灰尘模板的KrakenJs遍历对象错误

时间:2018-07-26 06:51:47

标签: node.js dust.js kraken.js

  

我应该拥有else部分,但出现错误:cart.items的预期结束标记,但未找到。在第21行,第35列。我不知道问题出在哪里,一切都很好,可能是缩进错误,请注意代码并建议我。感谢也附有错误的屏幕截图。   这是我的灰尘文件:

{>"layouts/master" /}
    {<body}
     <div class="row">
        <div class="container">
            <h2>Your Cart</h2>
            {?cart.items}
                <table>
                    <thead>
                        <tr>
                            <th>Item</th>
                            <th>Quantity</th>
                            <th>Total</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        {#cart.items}
                            <tr>
                                <td><a href="books/details/{._id}">{title}</a></td>
                                <td>{.qty}</td>
                                <td> ${@math key="{.price}" method="multiply" operand ="{.qty}"}</td>
                                <td><a href="#" class="btn btn-danger">Remove</a></td>
                            </tr>
                        {/cart.items}
                    </tbody>
                </table>
                <div class="row">
                        <div class="col-sm-6">
                           <h4> Total <strong>${cart.total}</strong></h4>
                        </div>

                        <div class="col-sm-6">

                       </div>
                </div>
                {:else}
                    <p>There is no Items in your cart</p>
            {/cart.items}
        </div>
     </div>

    {/body}
  

这是我的控制器

    'use strict';

var Book = require('../models/bookModel');
var Category = require('../models/categoryModel');

module.exports = function (router) {
    router.get('/', function (req, res) {
        var cart = req.session.cart;
        var displayCart = {
            items: [], total: 0
        };

        var total = 0;
        //get total

        for(var item in cart){
            displayCart.items.push(cart[item]);
            total += (cart[item].qty * cart[item].price);
        }
        displayCart.total = total;

        res.render('cart/index', {cart: displayCart});
    });
 });
  

我遇到此错误:

this is error screen shot

1 个答案:

答案 0 :(得分:0)

应关闭数学助手。例如:

{@math key="{.price}" method="multiply" operand ="{.qty}" /}