I am in process of learning and using Backbone.js.
I have an Item model and a corresponding Item view. Each model instance has item_class and item_id attributes, that I
You can set the properties className
and id
on the root element:
http://documentcloud.github.com/backbone/#View-extend
var ItemView = Backbone.View.extend({
tagName: "div", // I know it's the default...
className : 'nice',
id : 'id1',
render: function() {
$(this.el).html("Some stuff");
}
});
EDIT Included example of setting id based on constructor parameters
If the views are constructed as mentioned:
var item1 = new ItemModel({item_class: "nice", item_id: "id1"});
var item2 = new ItemModel({item_class: "sad", item_id: "id2"});
Then the values could be set this way:
// ...
className: function(){
return this.options.item_class;
},
id: function(){
return this.options.item_id;
}
// ...