在玉这是如何解释? <%= lastName%>
我目前有这样的代码,但名字显示的方式显示。 我想弄清楚这是玉是什么,因为这是不对的。
玉文件
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(); })();
就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 %>">
从文件 :
由
=
缓冲的代码默认为了安全而被转义,但是要输出你可能使用的非转义的返回值!=
:p!= aVarContainingMoreHTML
另外请注意, 如果您使用的是旧版本的Jade ,则script
元素的内容可能会被整体视为文本文字。
Jade版本0.31.0弃用隐式文本只支持脚本和样式。 要解决这个问题,你只需要添加一个
.
脚本或样式标记之后的字符。
在0.31.0之前,您的视图将呈现为( 删节 ):
<script id="userEditTemplate" type="text/template"> div.userProfile form(action="#") # ... </script>
- 集成骨干与Nodejs
- 为Node.js服务器+ SPA javascript框架设置自动化BDDtesting环境的简单方法?
- 为什么Phantom.js没有评估我的Backbone应用程序的工作?
- Mongoose findByIdAndUpdate / findById返回null作为模型
- 处理API模型validation错误以发送回客户端
- 从localStorage转换Backbone的Todo List示例
- Dropzone.js状态处于挂起状态,不上传文件
- cross domain CORS支持backbone.js
- Backbone.js – 在ajax中获取视图,模型或集合属性'beforeSend'