5

I have a json object in the following format:

{
    properties:{
                  url:"http://..."
               }
}

And I want to display the url in a Backgrid grid. However, I can't figure out how to change the name attribute of the column such that it accesses the nested url. I have tried the following examples to no avail:

{
    name: "properties.url",
    label: "URL",
    cell: "uri"
}

And

{
    name: "properties[url]",
    label: "URL",
    cell: "uri"
}

It seems like a simple enough thing to do but I can't find an answer.

anubhavashok
  • 532
  • 3
  • 15

2 Answers2

5

Take a look at Backbone's Wiki.

There are at least 4 choices:

Y.H Wong
  • 7,151
  • 3
  • 33
  • 35
2

This is the entireity of "backbone-dotattr"

(function(_, Backbone) {
    _.extend(Backbone.Model.prototype, {
        get: function(key) {
            return _.reduce(key.split('.'), function(attr, key) {
                if (attr instanceof Backbone.Model)
                    return attr.attributes[key];

                return attr[key];
            }, this.attributes);
        }
    });
})(window._, window.Backbone);

with this, i can specify

name: "child.childAttribute" 
  • works perfectly in the "columns" part for Backgrid. hope it helps.