0
<script id="index-recipe" type="text/x-handlebars-template">
<h2>{{name}}</h2>
</script>
<script type="text/javascript">
var MyNamespace = { Views: {}};
$(document).ready(function() {
var template = Handlebars.compile($("#entry-template").html());
var templateRecipe = Handlebars.compile($("#index-recipe").html());
var recipes = [name = "Chicken Chilly", name = "Chicken Manchurian"];
MyNamespace.MyTagView = Backbone.View.extend({
template: templateRecipe,
initialize: function() {
this.render();
},
render: function() {
this.$el.html(this.template(this));
var ViewRecipes = new MyNamespace.Recipes({ collection: recipes });
this.$el.append(ViewRecipes.render().el);
return this;
}
});
MyNamespace.Recipes = Backbone.View.extend({
render: function() {
this.collection.forEach(function (recipe) {
var ViewRecipe = new Backbone.Recipe({ model: recipe });
this.$el.append(ViewRecipe.render().el);
}, this)
return this;
}
});
MyNamespace.Recipe = Backbone.View.extend({
render: function() {
this.$el.text("I am Recipe");
return this;
}
});
var View = new MyNamespace.MyTagView();
$("#content").html(View.el);
});
</script>