dart - 按文本对 HtmlElements 列表进行排序

标签 dart

我正在尝试排序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/

相关文章:

flutter - "Text selection index was clamped (-1->0) to remain in bounds"在我的描述字段中

ios - 拉动以刷新 iOS 外观和感觉

flutter - Flutter:如何从流中获取所有数据,然后监听同一流中的新更新?

dart - 在Dart中的可选参数构造函数中使用构造函数初始化成员

android - flutter 运行和 Debug模式仅在物理 Android 设备中显示白屏

Flutter Test Mock GraphQL Mutation 结果

dart - 使用使用 DartSON 的库时出错

angularjs - 在 Angular Controller 初始化中调用dart函数

flutter - Flutter中如何在BottomNavigationBar中显示图片?

flutter - RenderBox的布局不整齐