我创建了一个带有本地化模板的主干示例代码。但我无法调试它为什么不起作用。请帮我。代码在以下路径中可用。
http://jsfiddle.net/nagesforyou/kdDMK/
var resource = {localizedHeader : "localized header in english"};
var BaseView = Backbone.View.extend({
localizedTemplate : function(element) {
self : this;
this.template = _.template(element.html());
return function(data) {
return self.template($.extend({},data,resource));
};
}
});
var DerivedView = BaseView.extend({
initialize: function(options) {
this.model = options.model;
this.template = this.localizedTemplate($("#someTemplate"));
},
render : function() {
var output = this.template(this.model.toJSON());
this.$el.append(output);
return this;
}
});
var someModel = Backbone.Model.extend({
});
var mdl = new someModle({someNmae : "surendhar"});
var derivedView = new DerivedView({model: mdl, el:$('body')});
derivedView.render();
<script type="text/template" id="someTemplate">
<div>
Sometext
<div> <%= localizedHeader%> </div>
<div> <%= someName %> </div>
</div>
</script>
Running....