Search code examples
backbone.jsunderscore.jsmarionettebackgrid

Backgrid.js error, "has no method 'omit'"?


I'm working on an app in Backbone and am trying to implement Backgrid.js, but I keep getting this error:

Uncaught TypeError: Object function (a){return new m(a)} has no method 'omit'

This occurs when the Backgrid.Grid is initializing and seems to be related to the columns. I have checked my syntax and even created a simplified column array with 1 item and a simplified collection object, with a single attribute matching the column.

var columns = [{name: 'year', label: 'Year', cell: 'string'}];
var data = [{year: '1964'}, {year: '1965'}];

My grid is initialized with:

var grid = new Backgrid.Grid({ columns: columns, collection: data});

Pretty simple and straightforward, but I am still getting this error. I have also checked my versions of Backbone, Underscore and they match what is included in the Backgrid.js download.

Anybody else come across this or have any ideas what might be causing the issue?


Solution

  • There's only one omit call in Backgrid:

    var passedThruOptions = _.omit(options, ["el", "id", "attributes",
                                             "className", "tagName", "events"]);
    

    and _.omit was added in Underscore 1.4.0 last September:

    1.4.0 — Sept. 27, 2012
    [...]

    • Added an omit function, for filtering an object to remove certain keys.

    So presumably you're using a version of Backgrid that expects at least Underscore 1.4.0 but your actually using an older version of Underscore. Try upgrading Underscore (and Backbone while you're at it) to the latest version.