我正在为enyo的csvparser.dart的分叉添加Iterable功能,以便与Angular Dart一起使用。通过添加mixin,CsvParser可以使用for..in
循环,但是ng-repeat
使用“RangeError:value 0”失败。
我通过延长Iterator
和IterableMixin
来做错事,但我被卡住了。
栈跟踪
RangeError: value 0
STACKTRACE:
#0 Iterator&IterableMixin.elementAt (dart:collection/iterable.dart:190)
#1 Scope.$watchCollection.<anonymous closure> (package:angular/core/scope.dart:397:60)
#2 relaxFnArgs2.<anonymous closure> (package:angular/utils.dart:49:47)
#3 Scope._digestHandleDirty (package:angular/core/scope.dart:613:24)
#4 Scope._digestComputeLastDirty (package:angular/core/scope.dart:564:36)
#5 Scope._digestWhileDirtyLoop (package:angular/core/scope.dart:489:52)
#6 Scope.$digest (package:angular/core/scope.dart:475:28)
#7 _autoDigestOnTurnDone (package:angular/core/scope.dart:153:14)
#8 _rootRun (dart:async/zone.dart:710)
#9 _ZoneDelegate.run (dart:async/zone.dart:440)
#10 NgZone._finishTurn (package:angular/core/zone.dart:91:21)
#11 NgZone._onRunBase (package:angular/core/zone.dart:56:43)
#12 _onRun (package:angular/core/zone.dart:61:15)
#13 _ZoneDelegate.run (dart:async/zone.dart:440)
#14 _CustomizedZone.run (dart:async/zone.dart:650)
#15 NgZone.run (package:angular/core/zone.dart:143:27)
#16 ngBootstrap (package:angular/bootstrap.dart:89:18)
#17 main (http://127.0.0.1:3030/staffing/web/main.dart:36:14)
csvparser.dart
class CsvParser extends Iterator with IterableMixin<CsvLineParser> {
...
Iterator<CsvLineParser> get iterator => this;
main.dart
@NgController(
selector: '[spreadsheet]',
publishAs: 'ctrl')
class SpreadsheetCtrl
{
// "first_name","last_name","company_name","address","city","county","state","zip","phone1","phone2","email","web"
String raw = '''
"James","Butt","Benton, John B Jr","6649 N Blue Gum St","New Orleans","Orleans","LA",70116,"504-621-8927","504-845-1427","jbutt@gmail.com","http ://www.bentonjohnbjr.com"
"Josephine","Darakjy","Chanay, Jeffrey A Esq","4 B Blue Ridge Blvd","Brighton","Livingston","MI",48116,"810-292-9388","810-374- 9840","josephine_darakjy@darakjy.org","http://www.chanayjeffreyaesq.com"
"Art","Venere","Chemel, James L Cpa","8 W Cerritos Ave #54","Bridgeport","Gloucester","NJ","08014","856-636-8749","856-264-4130","art@venere. org","http://www.chemeljameslcpa.com"
''';
CsvParser data;
SpreadsheetCtrl()
{
data = new CsvParser(raw);
}
}
class MyAppModule extends Module {
MyAppModule() {
type(SpreadsheetCtrl);
}
}
void main() {
ngBootstrap(module: new MyAppModule());
}
的index.html
<div spreadsheet>
<table>
<tr ng-repeat="row in ctrl.data">
<td ng-repeat="col in row">
{{col}}
</td>
</tr>
</table>
...
<script type="application/dart" src="main.dart"></script>
test.dart
import 'web/csvparser.dart';
main()
{
String raw = '''
"first_name","last_name","company_name","address","city","county","state","zip","phone1","phone2","email","web"
"James","Butt","Benton, John B Jr","6649 N Blue Gum St","New Orleans","Orleans","LA",70116,"504-621-8927","504-845-1427","jbutt@gmail.com","http://www.bentonjohnbjr.com"
"Josephine","Darakjy","Chanay, Jeffrey A Esq","4 B Blue Ridge Blvd","Brighton","Livingston","MI",48116,"810-292-9388","810-374-9840","josephine_darakjy@darakjy.org","http://www.chanayjeffreyaesq.com"
"Art","Venere","Chemel, James L Cpa","8 W Cerritos Ave #54","Bridgeport","Gloucester","NJ","08014","856-636-8749","856-264-4130","art@venere.org","http://www.chemeljameslcpa.com"
''';
CsvParser data = new CsvParser(raw);
for(var row in data)
{
for(var col in row)
{
print('${col}, ');
}
}
}
答案 0 :(得分:0)
如果集合和迭代器是同一个类(我不知道为什么),这似乎不起作用。
创建一个额外的CsvIterator
类,并在CsvIterator
的实现中返回CsvParser
的实例,而不是this
。
class CsvIterator extends Iterator<CsvLineParser> {
CsvParser data;
MyIterator(this.data);
... // implementation
}
class CsvParser extends Object with IterableMixin<CsvLineParser> {
...
Iterator<CsvLineParser> get iterator => new CsvIterator(this);
}