【问题标题】:Backgrid template not rendering Backgrid.Cell.ExtendBackgrid 模板不呈现 Backgrid.Cell.Extend
【发布时间】:2015-01-10 21:52:01
【问题描述】:

我是这个网站的新手,所以如果我弄错了,请原谅我,但我在下面找到了问题/答案并尝试将其合并到我自己的代码中,但我在渲染模板时遇到问题.

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('&lt;button&gt;Delete&lt;/button&gt;'),但得到了相同的结果。

虽然我已经编码多年,但基于 Web 的开发对我来说还是个新手,我正在学习 Bootstrap、Angular、Backbone 和 Backgrid 的速成课程。如果您在此处提供任何支持或建议,我将不胜感激。

谢谢 李

【问题讨论】:

    标签: twitter-bootstrap backbone.js backgrid


    【解决方案1】:

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

    通过将 render() 函数更改为

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

    我能够正确显示图标。显然 ASP 1.0 的日子已经一去不复返了,那是我最后一次进行真正的 Web 开发! :-)

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

    干杯, 李

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      • 2019-02-02
      相关资源
      最近更新 更多