我正在尝试排序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
的类
我得到了异常(exception)
Unsupported operation: Cannot sort element lists
有解决办法吗还是我必须手动完成?
最佳答案
我还没有尝试过,但我认为当您添加 .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)));
});
关于dart - 按文本对 HtmlElements 列表进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24271005/