我有以下内容
name: "id", // The key of the model attribute
label: "User Id", // The name to display in the header
editable: false, // By default every cell in a column is editable, but *ID* shouldn't be
cell: Backgrid.UriCell.extend({
orderSeparator: ''})
}, {
使用Backgrid.UriCell
具有
href: formattedValue,
title: formattedValue**,
有什么方法可以定义href
"session" + formatedValue
?换句话说,如何自定义UriCell
以便我可以定义与标题不同的href
?
试试这个:
var UriCell = Backgrid.UriCell.extend({
render: function () {
this.$el.empty();
var rawValue = this.model.get(this.column.get("name"));
var formattedValue = this.formatter.fromRaw(rawValue, this.model);
var href = _.isFunction(this.column.get("href")) ? this.column.get('href')(rawValue, formattedValue, this.model) : this.column.get('href');
this.$el.append($("<a>", {
tabIndex: -1,
href: href || rawValue,
title: this.title || formattedValue,
target: this.target
}).text(formattedValue));
this.delegateEvents();
return this;
}
});
然后,你可以这样写:
name: "id",
label: "User Id",
editable: false,
cell: UriCell,
href: function(rawValue, formattedValue, model){
return "session" + formattedValue;
}