Spine view parent?
How do I set the parent of a view in trunk mode?
var TodosView = Backbone.View.extend({
tagName: 'p', // required, but defaults to 'div' if not set
className: 'container', // optional, you can assign multiple classes to
// this property like so: 'container homepage'
id: 'todos', // optional
initialize: function(){
// debugger
this.$el.html("bamboo4a")
$("body").append(this.$el);
}
});
var todosView = new TodosView();
I don't want to write $ ("body"). append
+3
source to share
1 answer
For the main view, you can set the view element when you create the view object by passing it to the constructor (namely the option el
).
var MyView = Backbone.View.extend({
template: '<p>Hello World!</p>',
render: function() {
this.$el.html(this.template);
}
});
new MyView({
el: 'body' // or el: '#content' and so on
}).render();
+2
source to share