模板重复不适用于嵌套列表(Polymer.dart) [英] Template repeat not working for nested list (Polymer.dart)
问题描述
由于缺乏dart中的多维数组支持,我想到使用List。
Due to the lack of multi-dimensional array support in dart, I thought of using List.
Dart代码:
class MyModel extends Object with Observable {
@observable
List<List<int>> dataList = toObservable(new List<List<int>>());
}
void main() {
initPolymer().run(() {
Polymer.onReady.then((_) {
var template = querySelector("#bindValueTemplate") as AutoBindingElement;
var model = template.model = new MyModel();
for (int i=0; i<2;i++) {
List<int> in1 = new List<int>();
for (int j=0; j<2; j++) {
in1.add(j);
}
model.dataList.add(in1);
}
});
});
}
HTML档案(片段) >
HTML file (snippet):
<body fullbleed touch-action="auto">
<template id="bindValueTemplate" is="auto-binding-dart">
<div id="dynamic_area" layout horizontal>
<table template repeat="{{row in dataList}}">
<tr template repeat="{{col in row}}">
<td>{{col}}</td>
</tr>
</table>
</div>
</template>
</body>
我在控制台中遇到错误:
Uncaught Error: Error evaluating expression 'row': Class 'MyModel' has no instance getter 'row'.
NoSuchMethodError: method not found: 'row'
Receiver: Instance of 'MyModel'
Arguments: []
当在MyModel中使用getter添加'row'列表变量时,它会引发以下错误:
When I added a 'row' list variable in MyModel with a getter, it throws the following error :
未捕获错误:不支持的操作:无法评估in表达式
推荐答案
错误。 repeat子句应用于元素本身,而不是子元素。这解决了问题:
My understanding of template repeat was wrong. The repeat clause is to be applied for the the element itself, and not the children. This fixed the problem :
<body fullbleed touch-action="auto">
<template id="bindValueTemplate" is="auto-binding-dart">
<div id="dynamic_area" layout horizontal>
<table>
<tr template repeat="{{row in dataList}}">
<td template repeat="{{col in row}}">{{col}}</td>
</tr>
</table>
</div>
</template>
</body>
更新的dart代码:
class MyModel extends Object with Observable {
@observable
List<List<int>> dataList = toObservable(new List<List<int>>());
@observable
List<int> row = []; //I don't know why it works even without toObservable()
}
我将问题标记为已解决,因为我的具体问题已解决。但是问题仍然是如果我们实际想要重复表格元素!
I am marking the question as resolved because my specific problem was resolved. But the question still remains what if we actually want to repeat table elements !
这篇关于模板重复不适用于嵌套列表(Polymer.dart)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!