How can I call a function from jade client side java scripts

I have two dropdowns in my form. After the user selects a value from the first list, I want to filter the second list according to the selection and display. To do this, I use onchange = "showSubCat () from the first option to get the selected value. The showSubCat () function is defined in the client side js file. How to get the value returned by showSubCat () in the jade template so that I can filter an array that populates the second list.

var subcode = showSubCat(); 

gives an error.

Any suggestions? Thanks.

+4
source share
1 answer

New to Jade, but as far as I can tell, you have two options:

1) create a function in jade itself:

 -function sayHi(name){ - return "hello "+name -} p= sayHi('bill') 

I think your code is mutating a bit.

2) A better option would be to pass a function from a model

 app.get('/', function(req, res){ res.render('home', { title: 'Home' , fs: { sayHi:function(name){ return "hello "+name }} }); }); 

Then in your jade file you simply:

 p= fs.sayHi('bill') 
+4
source

Source: https://habr.com/ru/post/1399442/


All Articles