2014-03-02 56 views
1

的,我有以下如何自定义UriCell的渲染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与标题不同?

回答

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