0
我創建了具有本地化模板的主幹的示例代碼。但我無法調試爲什麼它不工作。請幫幫我。代碼在下面的路徑中可用。具有本地化模板的主幹
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....