0

私はレールと一緒にバックグリッドを使用しています。私の要件は、バックグリッドセルオプションの href 属性を変更することです。次のコードがあります

    var grid = new Backgrid.Grid({

     columns: [ {
      name: "location",
      cell: Backgrid.UriCell.extend({

      }),
      sortable: true,
      editable: false
     }]
    })

上記のコードは、次のように href 属性を「location-name」として使用してハイパーリンクを表示します

  <a tabindex="-1" href="location-name" title="location-name" target="_blank">location-name</a>

、しかし、次のように href 属性が必要です

  <a tabindex="-1" href="#some-id" title="location-name" target="_blank">location-name</a>

どうすればこれを行うことができますか、助けてください

4

2 に答える 2

0

ドキュメント (backgrid.js の 994 行目) を見ると、rawValue は列名から直接取得されており、渡すことができるオプションではありません。

  render: function () {
    this.$el.empty();
    var rawValue = this.model.get(this.column.get("name"));
    var formattedValue = this.formatter.fromRaw(rawValue, this.model);
    this.$el.append($("<a>", {
      tabIndex: -1,
      href: rawValue,
      title: this.title || formattedValue,
      target: this.target
    }).text(formattedValue));
    this.delegateEvents();
    return this;
  }

それでは、レンダーを独自のものでオーバーライドできますか?

cell: Backgrid.UriCell.extend({
 render: function () {
    this.$el.empty();
    var rawValue = //what ever you want to put in the href;
    var formattedValue = this.formatter.fromRaw(rawValue, this.model);
    this.$el.append($("<a>", {
      tabIndex: -1,
      href: rawValue,
      title: this.title || formattedValue,
      target: this.target
    }).text(formattedValue));
    this.delegateEvents();
    return this;
  }
}),
于 2014-06-12T13:38:17.657 に答える