I am writing a very simple backbone model/view display. Basically there is a json field called shortDescription, and it should be displayed into a . However my code is not showing empty no matter what value I set inside the view.
Here is the code, where am I doing wrong?
html code:
<div id="itemDetailContainer"></div>
<script type="text/template" id="itemDetailTemplate">
< h3 > <% shortDescription %> < /h3>
</script>
Javascript:
ItemModel = Backbone.Model.extend({
initialize: function () {}
});
ItemDetailView = Backbone.View.extend({
initialize: function () {
this.$el = $("#itemDetailContainer");
this.template = _.template($("#itemDetailTemplate").html());
_.bindAll(this, "render");
this.render();
},
render: function () {
this.$el.html(this.template(this.model.toJSON()));
return this;
}
});
var it = new ItemModel({"shortDescription": "short"});
var v = new ItemDetailView({model: it});
I figured out the issue. I should use <%= %> instead of <% %>.
Syntax mistake 🙁