我目前有这样的代码,但名字的显示方式与显示方式相同。我想弄清楚 Jade 中的这是什么,因为这是不对的。
Jade 文件
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
这里我将包含我的 main.js 文件,也许我在那里做错了。
主要.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();
})();
最佳答案
就杰德而言,"<%= firstName %>"
只是一个String
文字。但是,它将对其进行 HTML 编码:
<input type="text" class="firstName" value="<%= firstName %>">
要保持值不变,请添加 !
在 =
之前跳过编码。
input(type="text", class="firstname", value!="<%= firstName %>")
<input type="text" class="firstName" value="<%= firstName %>">
来自documenation :
Code buffered by
=
is escaped by default for security, however to output unescaped return values you may use!=
:p!= aVarContainingMoreHTML
另请注意,if you're using an older version of Jade , script
的内容元素可以整体视为文本文字。
Jade version 0.31.0 deprecated implicit text only support for scripts and styles. To fix this all you need to do is add a
.
character after the script or style tag.
在 0.31.0 之前,您的 View 将呈现为(删节):
<script id="userEditTemplate" type="text/template">
div.userProfile
form(action="#")
# ...
</script>
关于javascript - 在 Jade 中,这是如何解释的? <%= 姓氏 %>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17578049/