Skip to main content

I am using node.js express 4

at my index.jsindex.js routes file I have this

router.get('/', function(req, res, next) {  res.render('index', {items: myItemsdocs}); }}; 

at my index.hbsindex.hbs view I'm trying to use items as a javascript variable

<script type="text/javascript"> var jsItems = items; var name1 = jsItems[Object.keys(jsItems)[0]].itemName;  alert(name1); </script> 

but nothing happens .. how can I use items object I have in the client side javascript ?

my template engine is express-handlebars

I am using node.js express 4

at my index.js routes file I have this

router.get('/', function(req, res, next) { res.render('index', {items: myItemsdocs}); }}; 

at my index.hbs view I'm trying to use items as a javascript variable

<script type="text/javascript"> var jsItems = items; var name1 = jsItems[Object.keys(jsItems)[0]].itemName;  alert(name1); </script> 

but nothing happens .. how can I use items object I have in the client side javascript ?

my template engine is express-handlebars

I am using node.js express 4

at my index.js routes file I have this

router.get('/', function(req, res, next) {  res.render('index', {items: myItemsdocs}); }}; 

at my index.hbs view I'm trying to use items as a javascript variable

var jsItems = items; var name1 = jsItems[Object.keys(jsItems)[0]].itemName; alert(name1); 

but nothing happens .. how can I use items object I have in the client side javascript ?

my template engine is express-handlebars

Source Link
You Ma
  • 189
  • 1
  • 13

How to access local variables from res.render from client side javascript?

I am using node.js express 4

at my index.js routes file I have this

router.get('/', function(req, res, next) { res.render('index', {items: myItemsdocs}); }}; 

at my index.hbs view I'm trying to use items as a javascript variable

<script type="text/javascript"> var jsItems = items; var name1 = jsItems[Object.keys(jsItems)[0]].itemName; alert(name1); </script> 

but nothing happens .. how can I use items object I have in the client side javascript ?

my template engine is express-handlebars