Backgrid模板不呈现Backgrid.Cell.Extend

时间:2014-11-13 16:55:00

标签: twitter-bootstrap backbone.js backgrid

我是这个网站的新手,请原谅我,如果我弄错了,但我发现下面的问题/答案,并尝试将其纳入我自己的代码,但我有正在呈现模板的问题。

How to implement delete per row for backgrid

与上面的内容非常相似我试图在Backgrid列中显示一个Bootstrap Glyph图标以允许用户删除一行,这就是我所拥有的:

    //My custom DeleteCell
    var DeleteCell = Backgrid.Cell.extend({
        template: _.template('<span class=\"glyphicon glyphicon-home\"></span>'),
        events: {
          click: "deleteRow"
        },
        deleteRow: function (e) {
          e.preventDefault();
          this.model.collection.remove(this.model);
        },
        render: function () {
          this.el.html = this.template();
          this.delegateEvents();
          return this;
        }
    });

然后,当我初始化网格时,我有以下内容:

       function createBackgrid(collection){
        var columns = [
        {
            name: "id", // The key of the model attribute
            label: "Delete", // The name to display in the header
            editable: false, 
            cell: DeleteCell
        }, ...

网格显示每个列中的数据都很好,但应显示我的删除图标的第一列是空白。如果我单击单元格,则会从模型中正确删除该行。

与前一个问题一样,我也试过了_.template('<button>Delete</button>'),但我得到了相同的结果。

虽然我已经编写了多年,但基于网络的开发对我来说是新的,我正在参加Bootstrap,Angular,Backbone和Backgrid的速成课程。我很感激这里的任何支持或建议。

由于 李

1 个答案:

答案 0 :(得分:2)

好的,所以我想出来了 - 需要更多的毅力!

将render()函数更改为

render: function () {
          this.el.innerHTML = this.template();
          this.delegateEvents();
          return this;
        }

我能够正确显示图标。显然,ASP 1.0的时代早已不复存在,这是我最后一次真正的网络开发! : - )

也许这会帮助处于类似位置的其他人?!

干杯, 李