简体   繁体   English

从Jade模板调用Javascript函数不起作用

[英]Javascript function call from Jade template is not Working

I want to call javascript function from my JADE template. 我想从我的JADE模板调用javascript函数。 I tried solutions posted in forum. 我尝试了在论坛上发布的解决方案。 but still it gives me error like "undefined is not a function" 但仍然给我类似“未定义不是函数”的错误

My Javascript function is 我的Javascript函数是

 script.
   function addCommas(nStr) {
               return nStr;
       }

And i am calling this function from JADE template like - 我从JADE模板调用此函数,例如-

 td(style='width: 10%;') #{addCommas("12345")}

But i throws error as below - 但是我抛出如下错误-

undefined is not a function

Can anyone help me on this? 谁可以帮我这个事?

Thanks. 谢谢。

This template code adds a function to call in javascript on the client side: 此模板代码在客户端添加了一个函数来调用javascript:

  script.
      function addCommas(nStr) { return nStr; }

But this template code call a function on the server side but they undefined (according to the previous): 但是此模板代码在服务器端调用了一个函数,但它们未定义(根据前面的内容):

td(style='width: 10%;') #{addCommas("12345")}

So, if you want define and call fuction on the server side you need define a template for another her: 因此,如果要在服务器端定义和调用功能,则需要为另一个服务器定义模板:

- function addCommas(nStr) { return nStr; }

If you want to call this function on the client side, then leave it in the same definition, but it causes so for example: 如果要在客户端调用此函数,则将其保留在相同的定义中,但这会导致例如:

script.
  console.log( addCommas("12345") );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM