[英]In Jade how is this interpreted ? <%= lastName %>
I currently have my code like this but the first name appears the way it is being shown. 我目前有这样的代码,但是名字以显示方式显示。 I am trying to figure out what this is in jade, because this is not right.
我试图弄清楚这在玉中是什么,因为这是不对的。
Jade File 玉锉
div.centerContent
script(type="text/javascript", src="/js/main.js")
h4 User goes here with equal before it no space
div#user
p!= "<%=firstName%>"
| <%=lastName%>
p!="<%= email %>"
p <%=phone%>
p <%=birthday%>
button.edit Edit
script(id="userTemplate", type ="text/template")
p <%=firstName%> <%=lastName%>
p <%=email%>
p <%=phone%>
p <%=birthday1%>
button.edit Edit
script(id="userEditTemplate", type ="text/template")
div
form(action="#")
input(type="text", class="firstName", value="<%= firstName %>") input(type="text", class="lastName", value="<%= lastName %>")
input(type="email", class="email", value="<%= email %>")
input(type="date", class="birthday", value="<%= birthday %>")
button.save Save
button.cancel Cancel
hr
Here I will include my main.js file maybe I am doing something wrong there. 在这里,我将包含我的main.js文件,也许我在那里做错了。
main.js main.js
(function () {
window.App = {
Models: {},
Collections: {},
Views: {},
Templates: {},
Router: {}
};
// MODEL
App.Models.User = Backbone.Model.extend({
defaults: {
firstName: 'first',
lastName: 'last',
email: 'Email',
phone: '222',
birthday: 'date'
},
validate: function (attrs) {
if (!attrs.firstName) {
return 'You must enter a real first name.';
}
if (!attrs.lastName) {
return 'You must enter a real last name.';
}
if (attrs.email.length < 5) {
return 'You must enter a real email.';
}
if (attrs.phone.length < 10 && attrs.phone === int) {
return 'You must enter a real phone number, if you did please remove the dash and spaces.';
}
if (attrs.city.length < 2) {
return 'You must enter a real city.';
}
},
initialize: function() {
user.on('invalid', function (model, invalid) {
console.log(invalid);
});
}
});
//VIEW
App.Views.User = Backbone.View.extend({
model: App.Models.User,
//tagName: 'div',
//id: 'user',
//className: 'userProfile',
template: _.template($("#userTemplate").html()),
editTemplate: _.template($("#userEditTemplate").html()),
initialize: function (){
}
render: function() {
this.$el.html(this.template(this.model.toJSON()));
return this;
},
events: {
'click button.edit': 'editProfile',
// 'click button.save': 'saveEdits',
'click button.cancel': 'cancelEdits'
},
editProfile: function () {
this.$el.html(this.editTemplate(this.model.toJSON()));
},
cancelEdits: function() {
this.render();
}
});
//start history service
Backbone.history.start();
var user = new App.Views.User({el: 'div #user'});
user.render();
})();
As far as Jade sees, "<%= firstName %>"
is just a String
literal. 据Jade所知,
"<%= firstName %>"
只是一个String
文字。 But, it will HTML encode it: 但是,它将对它进行HTML编码:
<input type="text" class="firstName" value="<%= firstName %>">
To keep the value as-is, add a !
若要保持原样的值,请添加
!
before the =
to skip encoding. 在
=
之前跳过编码。
input(type="text", class="firstname", value!="<%= firstName %>")
<input type="text" class="firstName" value="<%= firstName %>">
From the documenation : 从文档 :
Code buffered by
=
is escaped by default for security, however to output unescaped return values you may use!=
:为了安全起见,默认情况下,由
=
缓冲的代码会转义,但是要输出未转义的返回值,您可以使用!=
:p!= aVarContainingMoreHTML
Also note that, if you're using an older version of Jade , the contents of script
elements may be treated in whole as text literals. 还要注意, 如果您使用的是Jade的旧版本 ,
script
元素的内容可能会整体上视为文本文字。
Jade version 0.31.0 deprecated implicit text only support for scripts and styles.
Jade版本0.31.0弃用了隐式文本,仅支持脚本和样式。 To fix this all you need to do is add a
.
要解决此问题,您只需添加一个即可
.
character after the script or style tag.脚本或样式标签后的字符。
Before 0.31.0, your view would render as ( abridged ): 在0.31.0之前,您的视图将呈现为( 删节 ):
<script id="userEditTemplate" type="text/template">
div.userProfile
form(action="#")
# ...
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.