- Dart:Scalable Application Development
- Davy Mitchell Sergey Akopkokhyants Ivo Balbaert
- 201字
- 2021-07-09 18:56:31
Sorting the feature list
So far, no use has been made of the third piece of data in the coordinates list, which is the depth of the quake. This data will be presented in the form of a sorted list of the current features when the user presses the Sort button. Let's have a look at the following code snippet:
void sortFeatures(Event evt) { featPlotter.sortFeatures(); DivElement out = querySelector('#depthDetail'); out.nodes.clear(); featPlotter.geoFeatures.forEach((feature) { LIElement detail = new LIElement(); detail.innerHtml = "${feature[5]}km - ${feature[3]}"; out.nodes.add(detail); }); }
The list of features is sorted in the method sortFeatures
, and as Dart knows nothing of the meaning of the contents of the list, we provide a comparator function that decides which feature is deeper by comparing the depth measurement held at index 5
of the list:
List sortFeatures(){ geoFeatures.sort( (a,b) => a[5] - b[5] ); return geoFeatures; }
The comparator receives two arguments and returns 0
for items that are equal, a negative integer if a
is less than b,
or a positive integer if a
is greater than b
. Let's have a look at the following screenshot:

The depths are sorted in ascending order and presented as a simple bulleted list together with the location information.
- Vue.js快跑:構建觸手可及的高性能Web應用
- jQuery從入門到精通 (軟件開發視頻大講堂)
- 表哥的Access入門:以Excel視角快速學習數據庫開發(第2版)
- JavaScript入門經典
- R大數據分析實用指南
- Mastering Android Game Development
- Test-Driven Machine Learning
- Fast Data Processing with Spark(Second Edition)
- Django 3.0入門與實踐
- ExtJS Web應用程序開發指南第2版
- Scala編程(第5版)
- 單片機原理及應用技術
- App Inventor少兒趣味編程動手做
- 30天學通C#項目案例開發
- 軟件開發中的決策:權衡與取舍