我试图按List<HtmlElement>对Text进行排序,文本被解析为num
this.onClick.listen((e){
this.parent.nextElementSibling.children.sort((Row a,Row b)=>
num.parse(a.children[this.visibleIndex].text).
compareTo(num.parse(b.children[this.visibleIndex].text)));
}); Row是一个扩展HtmlElement的类。
我得到了例外
Unsupported operation: Cannot sort element lists周围有工作吗?还是我必须手动做?
发布于 2014-06-17 18:41:48
我还没有试过,但是我认为当添加.toList()时,它应该能工作。我认为这应该把它复制到一个可排序的标准列表中。
this.onClick.listen((e){
this.parent.nextElementSibling.children.toList().sort((Row a,Row b)=>
num.parse(a.children[this.visibleIndex].text).
compareTo(num.parse(b.children[this.visibleIndex].text)));
}); 发布于 2014-09-07 13:36:46
import 'dart:html';
UListElement list;
ButtonInputElement boton;
main() {
list = querySelector('#list');
boton.onClick.listen( (e) => sort() );
}
void sort(){
list.children = list.children.toList()
..sort((LIElement x, LIElement y)=> y.text.length.compareTo(x.text.length) );
}https://stackoverflow.com/questions/24271005
复制相似问题