2

如何在不将其定义为列之一的情况下将行号分配给背景网格的行?我想从 1 开始分配行号;标题中有或没有文本

4

2 回答 2

1

您现在可以像这样稍微低效地执行此操作:

var RowNumberCell = Backgrid.StringCell.extend({
  render: function () {
    return this.model.collection.indexOf(this.model) + 1;
  }
});

var columns = [{
  name: "",
  cell: RowNumberCell,
  editable: false,
  sortable: false
},
...
];
于 2014-01-23T09:39:02.733 回答
1

我不得不对 YH Wong 的回答稍作修改,因为我不断收到以下错误。

“节点”:参数 1 不是“节点”类型

通过使用以下代码,我能够获得所需的行为,尽管使用了相同的效率稍低的方法。

// Row Number Cell.
var RowNumberCell = Backgrid.StringCell.extend({
    render: function () {
        const number = this.model.collection.indexOf(this.model) + 1;
        this.$el.text(number);
        return this;
    }
});
于 2016-06-23T18:58:22.823 回答