聚合物表达式按名称访问属性

时间:2014-12-15 13:21:07

标签: dart dart-polymer

尝试将表格渲染为聚合物元素

      <table>
          <thead>
            <tr>
               <th template repeat='{{ column in columns}}'>
                  {{column.displayName}}
               </th>
           </tr>
         </thead>
         <tbody>
            <tr template repeat='{{ row in data}}'>
               <td template repeat='{{ column in columns}}'>
                 {{row[column.name]}}
               </td>
            </tr>
         </tbody>
      </table>

以下表达似乎不像我预期的那样工作

{{row[column.name]}}

column.name是我想要在行对象中访问的属性名称,但它为所有属性提供以下异常

NoSuchMethodError: method not found: '[]'
Receiver: Instance of 'Product'
Arguments: ["id"]

这是通过名称访问属性的正确方法吗?

我的行模型看起来像这样

class Product extends Observable{
  int id;
  String name;
  String category;
}

我不喜欢的一项工作是重载行类中的[]

operator [](String fieldName){
    var im = reflect(this);
    return im.getField(new Symbol(fieldName)).reflectee;
}

1 个答案:

答案 0 :(得分:2)

如果&#39; row&#39;是一张地图。