我目前的代码是这样的,但是第一个名字就像它的显示方式一样。我想弄清楚这是什么在玉,因为这是不对的。
玉文件
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文件,也许我在那里做错了。
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();
})();
答案 0 :(得分:2)
就Jade而言,"<%= 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:
默认情况下,
=
缓存的代码会被转义为安全性,但要输出未使用的返回值,您可以使用!=
:p!= aVarContainingMoreHTML
另请注意,if you're using an older version of Jade,script
元素的内容可以整体视为文字文字。
Jade版本0.31.0已弃用隐式文本仅支持脚本和样式。要解决此问题,您需要在脚本或样式标记之后添加
.
字符。
在0.31.0之前,您的视图将呈现为(删节):
<script id="userEditTemplate" type="text/template">
div.userProfile
form(action="#")
# ...
</script>