Reputation: 125
Is it possible, to repeat templates inside a template ? I`d like to have something like this:
<polymer-element name="polymer-mylement">
<template>
<div class="col-xs-12 col-sm-12 col-md-12">
{{ myobject.stringone }}
<br>
{{ myobject.stringtwo }}
<br>
<table>
<tbody>
<tr template repeat="{{ a in myobject.as}}" >
<td>{{ a.type }}</td>
<tr template repeat="{{ b in a.bs }}">
<li>
{{ b.type }}
</li>
</tr>
</tr>
</tbody>
</table>
</div>
</template>
<script type="application/dart" src="polymer_myelement.dart"></script>
</polymer-element>
polymer_mylement.dart
import 'dart:html';
import 'dart:core';
import 'package:polymer/polymer.dart';
import 'dart:typed_data';
import 'protobuf/***/myobject.pb.dart';
import 'package:custom_element/custom_element.dart';
import 'package:intl/intl.dart';
class MyObject {
String string1;
String string2;
List<a> as;
MyObject(this.string1, this.string2, this.as);
}
class a {
String type;
List<b> bs;
a(this.type, this.bs);
}
class b {
String type;
b(this.type);
}
@CustomTag('polymer-myelement')
class MyObjectElement extends PolymerElement with ObservableMixin {
bool get applyAuthorStyles => true;
@observable MyObject myobject;
}
main() {
void onDataLoaded(ByteBuffer response) {
Uint8List li = new Uint8List.view(response);
MyObject myobject = new MyObject.fromBuffer(li);
List<a> as = new List();
List<b> bs = new List();
for(final a in myobject.as) {
for (final b in a.bs){
bs.add(new b(b.type));
}
as.add(new a(a.type.toString(), bs));
}
MyObject myobject = new MyObject(myobject.string1, myobject.string2, as);
var myElem = createElement('polymer-myelement');
MyObjectElement moele = myElem.xtag;
moele.myobject = myobject;
query('.container').children.add(myElem);
}
query('#menu-mylement').onClick.listen((MouseEvent event){
query('.container').children.clear();
try {
var url = "*****";
var request = new HttpRequest();
request.open('GET', url);
request.responseType = "arraybuffer";
request.onLoad.listen((event) => onDataLoaded(event.target.response)
//print('Request complete ${event.target.response}')
);
request.send();
}
catch (e) {
print(e);
}
});
}
As you can see i have a MyObject which contains a List. Listelements of "a" have another List. In generell, in my main() method i fetch some protobuf data from our WebService. In my onDataLoaded i translate the binary string back to an readable format. Now i create my MyObject and fill it with ListElements via some Loops through my Response.
In my template, i would like to render the result.
It works till the second template repeat. I see string 1 and string2 from MyObject and also see the types from the List. But he doesnt show me the second repeat for my List ?
Is it possible or am i doing something mandatory wrong ?
Upvotes: 4
Views: 588
Reputation: 3980
See my comment above. It may just be that the browser's refusing to render the results of that second template because it's a tr
inside a tr
. Here's a JavaScript version of your code that seems to be working fine after switching to a td
.
Upvotes: 1