【问题标题】:displaying nested attributes in backgrid在 backgrid 中显示嵌套属性
【发布时间】:2014-03-22 10:26:44
【问题描述】:

我有一个 json 对象,格式如下:

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

我想在 Backgrid 网格中显示 url。但是,我不知道如何更改列的 name 属性以使其访问嵌套的 url。我尝试了以下示例均无济于事:

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

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

这似乎是一件很简单的事情,但我找不到答案。

【问题讨论】:

    标签: backgrid


    【解决方案1】:

    看看 Backbone 的Wiki

    至少有4个选择:

    【讨论】:

      【解决方案2】:

      这就是“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);
      

      有了这个,我可以指定

      name: "child.childAttribute" 
      
      • 在 Backgrid 的“列”部分中完美运行。希望对您有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-19
        • 2015-08-16
        • 2013-06-05
        相关资源
        最近更新 更多