<script type="text/template" id="date-cell">
<%= date.dateBegin %> até <%= date.dateEnd %>
<br>
<%= date.timeBegin %> até <%= date.timeEnd %>
</script>
<script type="text/template" id="status-cell">
<% if (order.enable) { %>
<% _.each(order.contacts, function(contact) { %>
<span class="contact-type"><%= contact.value %></span>
<% }); %>
<% } else { %>
<% if (order.expired) { %>
<span class="label label-expired">Expirado</span>
<% } else { %>
<span class="label label-closed">Fechado</span>
<% } %>
<% } %>
</script>
<script type="text/javascript">
var onRefreshGrid;
$(function() {
var Order,
OrderCollection,
orders,
grid;
Order = Backbone.Model.extend({});
OrderCollection = Backbone.Collection.extend({
modal: Order,
url: 'http://localhost:2000/orders.php'
});
orders = new OrderCollection();
var columns = [{
name : "hash",
label: "Cod. Pedido",
cell : 'string',
editable: false
},
{
name : "user",
label: "Nome",
cell: "string",
editable: false
},
{
name : "order",
label: "Status",
cell : Backgrid.StringCell.extend({
template: _.template($('#status-cell').html()),
render: function () {
this.$el.html(this.template(this.model.attributes));
return this;
}
}),
editable: false
},
{
name : "date",
label: "Data",
cell: Backgrid.StringCell.extend({
template: _.template(
$('#date-cell').html()
),
render: function() {
this.$el.html(this.template(this.model.attributes));
return this;
}
}),
editable: false
}];
// Initialize a new Grid instance
grid = new Backgrid.Grid({
columns: columns,
collection: orders
});
// Render the grid and attach the root to your HTML document
$('#datagrid').append(grid.render().el);
onRefreshGrid = function () {
orders.fetch({});
};
// auto execute
onRefreshGrid();
});
</script>
我需要根据条件为每一行(tr)添加背景颜色,正在查看遇到“Backgrid.Row.extend”的文档,您可以做什么,只是我需要创建一个基本模板..在每一行(tr)中复制,只是我也有一些列costumizo,如代码所示。我的问题是..您可以添加一个事件来监听每一行,而我只能更改其属性而不破坏结构(html)?