backgrid抛出TypeError

时间:2013-03-01 21:44:49

标签: backbone.js backgrid

我在backgrid第1620行收到此错误:

Uncaught TypeError: Cannot call method 'text' of null

这是我的代码,它模仿了这个例子:

var ConversionTag = Backbone.Model.extend({});
var ConversionTagCollection = Backbone.Collection.extend({
    model: ConversionTag,
    url: '/api/tags/conversion',
    parse: function(response, options) {
        return response.conversionTags;
    }
});

var tags = new ConversionTagCollection();

var init = function(parentSelector) {
    var columns = [
        { name: 'chanId', label: 'Channel', cell: 'integer' },
        { name: 'name', label: 'Description', cell: 'string' },
        { name: 'pageUrl', label: 'Conversion URL', cell: 'string' },
        { name: 'secureFl', label: 'Secure Tag', cell: 'integer' },
        { name: 'id', label: 'ID', cell: 'integer', editable: false }
    ];
    var grid = new Backgrid.Grid({
        columns: columns,
        collection: tags
    });
    var foo = grid.render().$el; // ERROR!
    $(parentSelector).append(foo);
    tags.fetch();
    window.ctags = tags;
    window.cgrid = grid;
};

错误发生在foo=行,tags.fetch永远不会被调用。

1 个答案:

答案 0 :(得分:0)

那是因为你试图将HTML注入标题中。 $ .text()调用document.createTextNode,它不接受HTML。你必须继承Header,明确声明它的用法in your column definition