2014-03-02 92 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; 
}