我刚开始在Backbone.js模板没有Backbone.js的
在这工作,我创建了使用显示在模板中的值的简单例子underscore.js
现在我想创造一些先进的例子使用模型的东西呈现在模板的用户的价值
现在我的模型(EditProfileModel.js):
个window.EditProfileModel = Backbone.Model.extend({
constructor : function(attributes, options) {
Backbone.Model.apply(this, arguments);
},
defaults : {
id : '',
firstName : '',
lastName : '',
},
urlRoot: 'rest/editProfile'
});
EditProfileView.js:
window.EditProfileView = Backbone.View.extend({
template : 'tpl/EditProfileTpl.html',
el: content,
initialize:function() {
this.render();
},
events: {
},
render:function() {
var $this = this;
var editProfileModel = new EditProfileModel({
id:this.model.get('id')
});
//GET editProfile/id
editProfileModel.fetch({
success : function(model){
//console.log("I am fetch " + JSON.stringify(model));
TemplateManager.get($this.template, function(template){
console.log($(template).html());
var html = _.template($(template).html(),{user : model});
$this.$el.html(html);
return $this;
});
}
});
},
});
与路由器的事情main.js是:
.....
routes : {
"profile/:id" : "editProfile"
},
editProfile : function(id){
var $this = this;
$this.model = new EditProfileModel({
id:id
});
$('#content').html(
new EditProfileView({
model: $this.model
})
);
}
......
TemplateManager仅仅是一个JavaScript代码,获取需求,并将其存储在模板该阵列并发送相同的模板,如果第二次从它的内存请求(我得到它的代码here)
但它的表现是这样的:
(见文本框的值应该是管理,因为它是从服务器返回)
请帮助我,这真是奇怪..... .............
:(
这是从服务器(模板)来的HTML :::
<div>
<form id="frmEditProfile" class="form-horizontal">
<div class="control-group">
<label class="control-label" for="firstName">FirstName</label>
<div class="controls">
<input id="firstName" name="firstName" placeholder="firstName" value="<%=model.get('firstName')%>" autofocus="autofocus">
</div>
</div>
<div class="control-group">
<label class="control-label" for="lastName">LastName</label>
<div class="controls">
<input type="text" id="lastName" name="lastName" placeholder="lastName">
</div>
</div>
<input type="hidden" name="id" value="">
<div class="control-group">
<div class="controls">
<button class="btn btn-primary" id="btnSave" type="submit">
<i class="icon-ok"></i> Save
</button>
</div>
</div>
</form>
</div>
您是否尝试过的模式注入之前解码HTML模板吗? – 2013-03-01 06:52:37