如何自定义UriCell的BackGrid渲染

时间:2014-03-02 06:53:53

标签: backgrid

我有以下

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

1 个答案:

答案 0 :(得分:0)

试试这个:

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;
}