harmony 鸿蒙Sorting by Indexes
Sorting by Indexes
When to Use
When there are many options in a list, users need to slide the window to search for the target option. Sorting by indexes is here to help them quickly find the target option by way of creating an index for each option. It is actually a kind of labeling. For example, labels ABCD on the right of the contact page correspond to the initial letters of contact names. If you want to find John, clicking J will direct you to a list of names starting with J. When there are many options in a list, users need to slide the window to search for the target option. Sorting by indexes is here to help them quickly find the target option by way of creating an index for each option.
How to Develop
For details about how to use related APIs, see IndexUtil.
Import the i18n module.
import { i18n } from '@kit.LocalizationKit';
Create an IndexUtil object.
let indexUtil: i18n.IndexUtil = i18n.getInstance(locale?: string); // locale is a string that indicates the locale ID. The default value is the current system locale ID.
Obtain the index list.
let indexList: Array<string> = indexUtil.getIndexList();
Obtain the index.
let index: string = indexUtil.getIndex(text: string);
Development Example
// Import the i18n module.
import { i18n } from '@kit.LocalizationKit';
// Create indexes in a single language.
let indexUtil: i18n.IndexUtil = i18n.getInstance('zh-CN');
let indexList: Array<string> = indexUtil.getIndexList(); // indexList = ['...', 'A', 'B', 'C', ... 'X', 'Y', 'Z', '...']
// Create indexes in multiple languages.
indexUtil.addLocale('ru-RU');
// indexList = ['...', 'A', 'B', 'C', ... 'X', 'Y', 'Z', '...', 'А', 'Б', 'В', ... 'Э', 'Ю', 'Я', '...']
indexList = indexUtil.getIndexList();
// Obtain the index of the string.
let index: string = indexUtil.getIndex('Nihao'); // index = 'N'
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Character Processing
harmony 鸿蒙Overview of Internationalization and Localization
harmony 鸿蒙Language and Locale Name Localization
harmony 鸿蒙Locale ID and Cultural Habit Division
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦