繁体   English   中英

将价值从Node JS转移到Jade

[英]Transfer value from Node JS to Jade

我正在尝试将参数从节点js传递到我的Jade页面中的Input Tag,这是我的代码:

节点js:

res.render("index" ,{title: userName});

Jade Page(称为“索引”):

.input
    input(type='text', value= #{title} ,  maxlength='15')

我在这里做错了什么?

这是我的错误信息:

48 | input(type ='text',value =#{title},maxlength = '15')

Function处的意外令牌ILLEGAL(本机)

`

它会按原样工作吗: value=title

.input
    input(type='text', value=title ,  maxlength='15')

您正在使用转义字符串插值,如此处所述: http : //jade-lang.com/reference/interpolation/这不能用作属性,您必须使用缓冲的代码,如此处所述: http:// jade- lang.com/reference/code/

它看起来像这样:

// escaped code
.input
    input(type='text', value= title ,  maxlength='15')
// unescaped code
.input
    input(type='text', value!= title ,  maxlength='15')

如果要使用对象作为属性,则可以使用input&attributes(object)来处理它,如此处所述: http : //jade-lang.com/reference/attributes/#and-attributes

Node.js

res.render("index" ,{
   input: {
      type: 'text',
      title: userName, 
      maxlength: '15',
      name: 'myInputName'
   }
});

玉:

.input
    input&attributes(input)

两者的结果:

<div class="input">
   <input type="text" value="username" maxlength="15" name="myInputName" />
</div>

这是Jade中不带节点的workinh Pen的示例: http ://codepen.io/pure180/pen/oLPGJy

暂无
暂无

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

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