編輯
我更新了我剛剛試過的一個例子的代碼。
我用DartEditor開發頻道和聚合物0.10.0-pre.12
編輯結束
我沒有嘗試的代碼,但我認爲它應該工作。 你需要更多的Dart/HTML樣板來製作一個有效的聚合物元素。 請參閱https://www.dartlang.org/polymer-dart/開始。
在聚合物元素中,您需要一個字段,該字段爲每個行保存一個具有值的集合。
的index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sample app</title>
<!-- import the test-element -->
<link rel="import" href="packages/polymer/polymer.html">
<link rel="import" href="test_element.html">
</head>
<body>
<h1>TestPolymer</h1>
<p>Sort observable</p>
<test-element></test-element>
</body>
</html>
test_element.html
<polymer-element name="test-element">
<template>
<style>
tr.foo {
background-color: #00ff00;
}
</style>
<table>
<tr template repeat="{{row in rows}}" class="{{ {'foo': row.contains('Approved')} }}">
<td template repeat="{{cell in row}}">{{cell}}</td>
</tr>
</table>
</template>
<script type="application/dart" src="test_element.dart"></script>
</polymer-element>
test_element.dart
library test_element;
import 'dart:async';
import 'package:polymer/polymer.dart';
@CustomTag('test-element')
class PeopleElement extends PolymerElement {
List<List<String>> rows = toObservable(// toObservable allows to update the HTML itself when the list content changes
[
['Row1-cell1', 'Row1-cell1', 'Row1-cell3', 'Approved'],
['Row2-cell1', 'Approved', 'Row2-cell3', 'Row2-cell4'],
['Approved', 'Row3-cell2', 'Row3-cell3', 'Row3-cell4'],
['Row4-cell1', 'Row4-cell2', 'Row4-cell3', 'Row4-cell4']
]);
PeopleElement.created() : super.created() {
print('PeopleElement');
}
}
我更新了我的答案。 –