How to pass Javascript LocalStorage Value in PUG

Viewed 344

I am getting Error while parsing Json LocalStorage variable in PUG/JADE

extends base.pug

block style
    style
        include ../static/trendbar.css

block scripts
    //- script(src="../static/jquery.js")
    //- script(src="../static/jquery2.js")

block content
    script!= "var items = []; items =JSON.parse(localStorage.getItem('obj')); console.log(items);"     
    .product
        h3.trendbar
            | Trending
        .row#loadProduct
            - var items1 = items;
            each n,i in items1
                .column
                    a.itemcon#cursor(href="/p/"+n.PID )
                        .pitem
                            .pitemMage
                                - var img = "../static/hookah/" + n.PID + ".jpg"
                                img(src= img alt ='NO MORE PRODUCT')
                            .pitemAvail
                                |   #{n.availability}
                            .pitemCost
                                p.prod_name
                                    |  #{n.name}
                                .prod_price
                                    p.realP
                                        |  ₹#{n.Mprice}
                                    p.ourP
                                        |  ₹#{n.Oprice}

TypeError: F:\hookahboi\views\trending.pug:18 16| .row#loadProduct

17|             - var items1 = items;

18| each n,i in items1

19|                 .column

20|                     a.itemcon#cursor(href="/p/"+n.PID )

21|                         .pitem

Cannot read property 'length' of undefined at eval (eval at wrap (F:\hookahboi\node_modules\pug-runtime\wrap.js:6:10), :188:32) at eval (eval at wrap (F:\hookahboi\node_modules\pug-runtime\wrap.js:6:10), :279:4) at template (eval at wrap (F:\hookahboi\node_modules\pug-runtime\wrap.js:6:10), :340:7)

0 Answers
Related