无法在jade块中运行javascript代码

时间:2013-05-29 06:41:02

标签: node.js pug nvd3.js

这是我的第一篇文章,所以请原谅任何格式问题。

我是Jade编程的新手,也是JS的新手。在使用Jade时,我无法在jade块中运行javascript。以下是我的Main.jade

extends layouts/standard
block pageContent
.container
  h1= title
  br
  .row
    #chart
      svg(style='height: 80px;')

script
nv.addGraph(function() {
      var chart = nv.models.bulletChart();

      d3.select('#chart svg')
          .datum(exampleData())
        .transition().duration(1000)
          .call(chart);

      return chart;
  });

  function exampleData() {
   return {"title":"Revenue","subtitle":"US$, in thousands","ranges":[150,225,300],"measures":[220],"markers":[250]};

block pageContent是standard.jade

正文中的一个块
html(ng-app="webApp")
head
    meta(charset="UTF-8")
    meta(http-equiv="content-type", content="text/html")
    meta(http-equiv="X-UA-Compatible", content="IE=edge")
    meta(name="viewport", content="width=device-width, initial-scale=1.0")
    link(rel="shortcut icon", type="image/x-icon", href="/images/favicon.ico")
    link(rel="stylesheet", type="text/css", href="/stylesheets/libs/css/libs.css")
    link(rel="stylesheet", type="text/css", href="/stylesheets/app/standard/app.css")
    script(type="text/javascript", src="/javascript/libs/libs.js")
    script(type="text/javascript", src="/javascript/app/app.js")
    //if lt IE 8
        script(type="text/javascript", src="/javascript/libs/respond/respond.js")
    include ../directives/menus/logo
    include ../directives/menus/main-nav-right
    include ../directives/menus/main-search-form
    body
    block pageContent

但是如果我将javascript直接粘贴到standard.jade的主体中;脚本被执行。运行脚本所需的nvd3.js和d3.js库包含在standard.jade头部的/javascript/libs/libs.js中

0 个答案:

没有答案