0

我正在尝试渲染一个包含四列的表格视图,“姓名”、“生日”、“性别”、“已婚”,但是

a)它们的列根本没有显示 b)我什至不确定我是否正确传递它们,因为当我 console.log table.options 列属性呈现为“空”:

Object {columns: Array[0], emptyContent: "no entries", onItemClick: function, sortable: false, onSort: null}

我试过这个:

var table = new Backbone.UI.TableView({
    model: people,
    columns: [
        { title: "Name", content: 'name' },
        { title: "Gender", content: "gender" } },
        { title: "Birthday", content: "birthday" } },
        { title: "Married", content: "married" }  }
    ]
});

和这个:

var table = new Backbone.UI.TableView({
    model: people,
    options: {
        columns: [
        { title: "Name", content: 'name' },
        { title: "Gender", content: "gender" },
        { title: "Birthday", content: "birthday" },
        { title: "Married", content: "married" }
        ]
    }
});
4

1 回答 1

2

The source code change is adding the options as mu is too short said. Change the initialize method of the Backbone.UI.TableView object to be the following within the source code:

initialize : function(options) { //add parameter
    Backbone.UI.CollectionView.prototype.initialize.call(this, arguments);
    $(this.el).addClass('table_view');
    this._sortState = {reverse : true};
    this.options = _.extend({}, this.options, options); //Add this line
}

I'm sure there might be a better place to put this but I'm just going through tutorials to learn some advanced backbone stuff considering the documentation does not match the current version I would shy away from using the library in production as of right now. Hopefully it is fixed in the future.

于 2014-05-02T14:58:48.363 回答