【问题标题】:How to customize the UriCell's render of BackGrid如何自定义 UriCell 对 BackGrid 的渲染
【发布时间】:2023-04-07 00:53:01
【问题描述】:

我有以下

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

【问题讨论】:

    标签: backgrid


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 2013-01-24
      • 1970-01-01
      • 2020-10-28
      • 1970-01-01
      • 2011-03-20
      • 2017-06-09
      • 2022-01-10
      • 2013-07-27
      • 1970-01-01
      相关资源
      最近更新 更多