Jade和jQuery在一起

Cma*_*mag 4 javascript jquery pug

伙计们,我如何在使用Jade生成的表单上实现jQuery样式?我想要做的是prettify形成并使它们可点击.用户界面我很糟糕.期.

我如何在表单上实现这个可选方法?http://jqueryui.com/selectable/

pendingArray是来自的JSON对象数组Express.只需要绘制它并使其可点击.点击一下,我想打开一个弹出窗口,我可以发布到我的api ...作为一个后端程序员,这个UI的东西完全超出了我的头脑,因为我从来没有花时间在这个空白.

page.jade:

include mainNavMenu

body
    h1= title
    p#container Welcome to #{title}
    p#message (to be filled in)
    script
        alert('hello world');
        $("#message").html("message set through jquery")

block Content

if (pendingArray)
    - each val, key in pendingArray
        <h1>#{val}</h1>
Run Code Online (Sandbox Code Playgroud)

tim*_*hew 10

你的问题不是Jade和jQuery,它是Jade和JavaScript;)

Jade尝试将您的JavaScript代码解释为Jade代码.您需要将JavaScript编写为纯文本.为了您的目的,您可以使用block in a tag语法,只需在以下后面添加一个script:

script.
    alert('hello world');
    $("#message").html("message set through jquery")
Run Code Online (Sandbox Code Playgroud)

来源:文件


循环中还有另一个错误.each是Jade语法而不是JavaScript,你也可以使用JavaScript代码循环,但这看起来不太好.在下一行中,您尝试编写纯文本/ HTML,但这不是简单的,请参见上文.

if pendingArray
    each item in pendingArray
        h1=val
Run Code Online (Sandbox Code Playgroud)

来源:文件